首页 > 试题广场 >

多组_A+B_零尾模式

[编程题]多组_A+B_零尾模式
  • 热度指数:14727 时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
给定若干组测试数据,最后一组数据为 0\ 0 ,作为输入的结尾。
每组数据有两个整数 ab ,请你求出 a+b 的值。

输入描述:
每行有两个整数 a\ (\ 0 \leq a \leq 10^9\ )b\ (\ 0 \leq b \leq 10^9\ )
最后一组数据为 0\ 0 ,作为输入的结尾。


输出描述:
输出若干行,每行一个整数,代表 a+b 的值。
示例1

输入

1 2
114 514
2024 727
0 0

输出

3
628
2751
#include <stdio.h>

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

发表于 2024-10-12 17:36:38 回复(3)
发表于 2024-09-11 15:30:39 回复(1)
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (true) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();

            if (a == 0 && b == 0) {
                break; 
            }

            System.out.println(a + b);
        }

        scanner.close();
    }
}

发表于 2025-03-08 16:32:42 回复(1)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a,b;
        //while 循环适用于循环次数不确定,直接在循环条件中进行判断
        while((a = input.nextInt()) != 0 & (b = input.nextInt()) != 0){
            System.out.println(a+b);
        }
    }
}
发表于 2025-06-16 13:27:10 回复(0)
import sys

for line in sys.stdin:
    a = line.split()
    if int(a[0]) !=0 and int(a[1]) != 0:
        print(int(a[0]) + int(a[1]))
    else:
        continue
发表于 2025-05-12 18:04:42 回复(0)
#include <stdio.h>

int main() {
    int a, b;
    while (scanf("%d %d", &a, &b) != EOF) {
    if (a == 0, b == 0 ) {
        break;
    }
        // 注意 while 处理多个 case
        // 64 位输出请用 printf("%lld") to
        printf("%d\n", a + b);
    }
    return 0;
}
发表于 2025-05-07 14:48:55 回复(0)
#include <stdio.h>

int main() {
    int a, b ,t, z;
    while (scanf("%d %d", &a, &b) != EOF) { // 注意 while 处理多个 case
        // 64 位输出请用 printf("%lld") to
        if(a==0&&b==0)
            return 0;
        printf("%d\n", a + b);
    }
    return 0;
}
发表于 2025-04-22 23:32:16 回复(0)
#include <iostream>
using namespace std;

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

发表于 2025-04-21 12:33:00 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        f:
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
            if (a==0&&b==0){break f;}
            System.out.println(a + b);
        }
    }
}
发表于 2025-04-18 11:04:40 回复(0)
import sys

for line in sys.stdin:
    a,b = map(int,line.split())
    if a==0 and b==0:
        break
    else:
        print(a+b)
发表于 2025-03-12 22:22:49 回复(0)
use std::io::{self, *};

fn main() {
    let Stdin = io::stdin();

    while let Some(Ok(line)) = Stdin.lock().lines().next() {
        let inputs = line.split(" ").collect::<Vec<_>>();
        let a =  inputs[0].parse::<i32>().unwrap();
        let b = inputs[1].parse::<i32>().unwrap();
        if a == 0 && b == 0 {
            break;
        }
        println!("{}", a+b);
    }
}
发表于 2025-02-23 22:00:34 回复(0)
#include <iostream>
using namespace std;

int main() {
    int a, b;
    while (cin >> a >> b) { // 注意 while 处理多个 case
        if(a==0&& b==0)
        {
            break;
        }
        cout << a + b << endl;
    }
}
发表于 2025-02-12 10:42:04 回复(0)
发表于 2025-02-07 15:00:57 回复(0)
while True:
    a,b = map(int,input().split(' '))
    if a == 0 and b == 0:
        break
    else:
        print(a+b)

发表于 2025-02-06 17:29:03 回复(0)
while True:
# Read input
line = input().strip()
# Split the input into two integers
a, b = map(int, line.split())
# Check for the termination condition
if a == 0 and b == 0:
break
# Print the sum of a and b
print(a + b)

发表于 2024-11-26 09:19:21 回复(0)
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
            if(a==b&a==0){
                continue;
            }else{
                System.out.println(a + b);
            }
        }
    }
}

发表于 2024-11-13 17:29:29 回复(0)
while True:
    # 读取一行并拆分成两个整数 a 和 b
    a, b = map(int, input().split())
    # 检查是否遇到结束条件 0 0
    if a == 0 and b == 0:
        break
    # 输出 a + b 的结果
    print(a + b)
发表于 2024-11-11 17:20:55 回复(0)
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
   
        while (a!=0 && b!=0) {
            System.out.println(a + b);
            a = in.nextInt();
            b = in.nextInt();
        }

    }
}
发表于 2024-10-30 16:00:03 回复(0)
while True:
        a, b = map(int, input("").split(" "))
        if a + b !=0:
            print(a + b)
        else:
            break

发表于 2024-10-16 23:28:20 回复(0)
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
   
        while (in.hasNextInt()) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = a + b;
            //计算出一行的结果后,先进行判断,因为最后一组数据以0 0 结尾,所有不为0时可以输出
            if(!(c==0)){
                System.out.println(c);
            }else{
                //如果为0时,则进行hasNextInt()判断,true则说明这不是最后一组,所有输出结果
                if(in.hasNextInt()){
                    System.out.println(c);
                }else{
                    break;
                }
            }
        }
    }
}
发表于 2024-09-25 11:32:24 回复(0)