第30591题 单选题
在C语言算法题场景下,针对未明确给出测试数据总组数的多组输入需求,以下处理方式正确的是?

假设每一组测试数据要求读取两个整数a、b,输出a+b的结果,无需考虑输入输出的其他格式约束。

A
int n;
scanf("%d", &n);
for(int i=0;i<n;i++) {
    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d\n",a+b);
}
B
int a,b;
while(scanf("%d%d",&a,&b) == 2) {
    printf("%d\n",a+b);
}
C
int a,b;
do {
    scanf("%d%d",&a,&b);
    printf("%d\n",a+b);
} while(true);
D
int a,b;
while(getchar() != EOF) {
    scanf("%d%d",&a,&b);
    printf("%d\n",a+b);
}
程序运行统计
暂无判题统计
提交0次 正确率0.00%
答案解析