Skip to content

Latest commit

 

History

History
73 lines (58 loc) · 1.08 KB

0003.A+B问题III.md

File metadata and controls

73 lines (58 loc) · 1.08 KB

3. A+B问题III

题目链接

C++

#include<iostream>
using namespace std;
int main() {
    int a, b;
    while (cin >> a >> b) {
        if (a == 0 && b == 0) break;
        cout << a + b << endl;
    }
}

Java

import java.util.Scanner;

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

python

import sys 
 
while True: 
    s = input().split() # 一行一行读取
    a, b = int(s[0]), int(s[1])
    if not a or not b: # 遇到 0, 0 则中断
        break
    print(a + b) 

Go

Js

C

#include <stdio.h>

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