UVa: UVA - 10719 Quotient Polynomial

以前遇到过类似的情况——在未知数组长度的情况下输入数组各元素,解决问题的关键是如何判断数组何时输入结束,经验以为OJ会以EOF结束输入,但RE了,以'\n'结束输入AC

#include
const int MAXN = 10100;
int p[MAXN];
int main(){
    int k;
    while(scanf("%d", &k) != EOF){
        int i = 0;
        char c;
        while(scanf("%d%c", &p[i], &c)){
            if(c == '\n')
                break;
            i++;
        }
        int temp;
        for(int j = 0; j <= i - 1; j++){
            if(j == 0){
                temp = p[0];
                printf("q(x): %d", temp);
            }
            else{
                temp = p[j] + k * temp;
                printf("%d", temp);
            }
            if(j != i - 1)
                printf(" ");
            else
                printf("\n");
        }
        printf("r = %d\n", p[i] + k * temp);
        printf("\n");
    }
    return 0;
}


你可能感兴趣的:(OJ:UVa,题目分类:数学基础)