杭电(1000)
A + B Problem
Problem Description
Calculate A + B.
Input
Each line will contain two integers A and B. Process to end of file.
Output
For each case, output A + B in one line.
Sample Input
1 1
Sample Output
2
Java
import java.util.Scanner;
public class Main
{
public static void main (String[] args)
{
Scanner reader=new Scanner(System.in);
while(reader.hasNextInt())
{
int a=reader.nextInt();
int b=reader.nextInt();
System.out.println(a+b);
}
} }
C
#include<stdio.h>
int main()
{
int a,b;
while((scanf("%d %d",&a,&b))!=EOF)
{
printf("%d\n",a+b);
}
return 0;
}
C++
#include<iostream>
using namespace std;
int main()
{
int a,b;
while(cin >>a >> b)
{
cout << a+b << endl;
}
return 0;
}

本文详细解析了杭电OJ平台上的经典A+B问题,提供了使用Java、C和C++三种语言的完整代码实现,适合初学者理解和实践基本的输入输出操作。
435

被折叠的 条评论
为什么被折叠?



