首页 > 试题广场 >

多组数据a+b III

[编程题]多组数据a+b III
  • 热度指数:19388 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
\hspace{15pt}计算多组测试用例中两个整数 a,b 的和。当输入的两个整数均为 0 时,表示输入结束,不再处理该组。

输入描述:
\hspace{15pt}多组测试用例,每行输入两个整数 a,b0 \leqq a,b \leqq 1000),用空格隔开。当且仅当 a=0b=0 时,输入结束,该组数据不处理。


输出描述:
\hspace{15pt}对于每组测试用例 a,b,输出一个整数,表示 a+b 的结果,每个结果占一行。
示例1

输入

1 1
2 2
0 0

输出

2
4

说明

第一组:1+1=2;第二组:2+2=4;遇到 0\ 0 后结束,不处理。
while 1:
    a,b=map(int,input().split())
    p=a==b==0
    if p:break
    print(a+b)

发表于 2025-10-28 10:49:21 回复(0)
#include <stdio.h>

int main() {
    int a, b;
    do {
        scanf("%d %d", &a, &b);
        if ((a != 0) && (b != 0))
            printf("%d\n", a + b);
    } while ((a != 0 ) && (b != 0));

    return 0;
}
发表于 2025-09-20 19:38:57 回复(0)
#include <iostream>
using namespace std;

int main() {
    for (;;){
        int a,b;
        cin>>a>>b;
        if(a==0&&b==0){
            return 0;//换成break也可以运行
        }else cout<<a+b<<endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")
发表于 2025-09-18 19:39:56 回复(0)
while True:
    a,b = map(int,input().split())
    if a==0 and b==0:
        break
    elif 0<a<=1000 and 0<b<=1000:
        print(a+b)

发表于 2025-12-17 22:03:58 回复(0)
#include <iostream>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    while (a != 0 || b != 0) {
        cout << a + b << endl;
        cin >> a >> b;//覆盖之前的a,b
    }
}

发表于 2025-12-11 00:03:00 回复(0)
import sys

for line in sys.stdin:
    a = line.split()
    if int(a[0])==0&int(a[1]) == 0:
        break
    else:
        print(int(a[0]) + int(a[1]))
发表于 2025-12-09 12:00:52 回复(0)
#include <iostream>
using namespace std;

int main() {
    int a,b;
    while(cin >> a >> b && a != 0 && b != 0){
        cout << a+b << endl;
    }
}

发表于 2025-12-09 01:01:00 回复(0)
while True:
    a,b=map(int,input().split())
    if a!=0 and b!=0:
        c=a+b
        print(c)
    else:
        break
发表于 2025-11-26 01:10:20 回复(0)
t = True
while t:
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        t = False
    else:
        print(a + b)

发表于 2025-11-09 23:55:02 回复(0)
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    while(cin>>a>>b)
    {
        if(a!=0&&b!=0)
        cout<<a+b<<endl;
    }
}

发表于 2025-11-09 16:54:48 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        //使用Scanner录入整数a,b
        Scanner sc=new Scanner(System.in);
        while(true){
            int a=sc.nextInt();
            int b=sc.nextInt();
            //a与b都为0时结束循环
            if(a==0&&b==0){
                break;
            }
            System.out.println(a+b);
        }
    }
}
发表于 2025-10-31 17:09:49 回复(0)
import sys
lines = sys.stdin.read().splitlines()
for line in lines:
    nums = list(map(int, line.split()))
    if sum(nums) != 0:
        print(sum(nums))
    else:
        sys.exit()

发表于 2025-10-31 10:31:51 回复(0)
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    // Write your code here
    while(line = await readline()){
        let tokens = line.split(' ');
        let a = parseInt(tokens[0]);
        let b = parseInt(tokens[1]);
        if (a+b != 0) {
        console.log(a + b);
        }
    }
}()
发表于 2025-10-30 16:27:04 回复(0)
#include<stdio.h>
int main()
   int a,b;
   while(1)
   {
     scanf("%d %d",&a,&b);
     if(a==0&&b==0)
     {break;}
     printf("%d\n",a+b);
   }
   return 0;
}
发表于 2025-10-30 14:49:29 回复(0)
#include <stdio.h>

int main() {
    int a,b;
   
    while  ((scanf("%d %d",&a,&b))&&a!=0&&b!=0) {
        printf("%d\r\n",a+b);
    }
    return 0;
}
发表于 2025-10-29 20:19:35 回复(0)
#include <iostream>
using namespace std;

int main() {
    int a,b;
   while(cin>>a>>b&&a!=0&&b!=0){
    cout<<a+b<<endl;
   }
}

发表于 2025-10-29 16:59:45 回复(0)
#include <stdio.h>

int main() {
    int a, b;
    for(;;){
        scanf("%d %d\n", &a, &b);
          if(a==0 && b==0)
        break;
        printf("%d\n", a + b);
       
    }
    return 0;
}


发表于 2025-10-27 20:21:04 回复(0)
#include <iostream>
using namespace std;

int main() {
    int a,b;
   
    for(;;) {
        cin>>a>>b;
        if(a==0 && b==0)
            return 0;
        else{
            cout<<a+b<<endl;
        }
    }
}
发表于 2025-10-18 14:05:58 回复(0)
#include <bits/stdc++.h>
using namespace std;

int main() {
    int a,b;
    while(cin>>a>>b&&a!=0&&b!=0){
        printf("%d\n",a+b);
    }
}

发表于 2025-10-01 19:04:03 回复(0)
while True:
    a,b=map(int,input().split())
    if a==0 and b==0:
        break
    print(a+b)
发表于 2025-09-28 23:33:16 回复(0)