while(true)的应用,上一题用了while(cin>>)

时间来过的沙漏 · 发布于 2022-01-20 · 浏览 678 回复 0

这题光用iostream读取容易超时,所以应该用scanf和printf

include

include

using namespace std;

int main() {

    int i=0;
    int n,a,b;
    scanf("%d",&n);
    int cnt[n];
    while(true)
    {

            scanf("%d%d",&a,&b);
            cnt[i]=a+b;
            i++;
            if(i==n)break;

    }
    for(i=0;i<n;i++)
    {
            printf("%d\n",cnt[i]);
    }
    return 0;

}

全部回复 共 0 条

还没有人回复。往下写第一条。

发表回复