杭电ACM2010:水仙花数

#include 
using namespace std;
int main(){
    int m, n;
    int a, b, c,flag=0;
    int x[1000];
    while (cin >> m >> n)
    {
        if (m > n){
            n = m + n;
            m = n - m;
            n = n - m;
        }
        for (int i = m; i <= n; i++){
            a = i % 10; b = (i / 10) % 10; c = i / 100;
            if (i == a*a*a + b*b*b + c*c*c){
                x[flag] = i;
                flag++;
            }
        }
        if (flag == 0) cout << "no" << endl;
        else{
            for (int i = 0; i < flag-1; i++)  //因为从0开始
                cout << x[i] << " ";
            cout << x[flag - 1] << endl;      //flag-1为最后一位
        }
        flag = 0;
    }
    return 0;
}

格式话输出是AC的关键

你可能感兴趣的:(菜鸟日记)