A+B Problem
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
Calculate a+b.
Input
Two integer a,b (0<=a,b<=10).
Output
Output a+b.
Sample Input
1 2
Sample Output
3
Hint
問:怎樣輸入輸出?
答:你的程序應該從標準輸入(stdin)中讀取數據,而將結果寫到標準輸出(stdout)。比如,在C語言中你可以使用“scanf”,在C++語言中則可以使用“cin”來輸入;輸出可以使用C語言的“printf”或者C++語言的“cout”。
注意:不要向標準輸出寫入題目要求輸出結果之外的其他數據,否則你會被判爲“Wrong Answer”,即錯誤的運行結果。
你的程序也不能試圖讀或寫任何文件,否則你可能被判爲“Runtime Error”(運行時錯誤)或“Wrong Answer”(錯誤結果)。
下面是這道題的一個C++或者G++的程序。
#include //請注意include的使用,如果使用#include 在G++編譯器上將出現“Compile Error”
using namespace std;
int main()
{
int a,b;
cin >> a >> b;
cout << a+b << endl;
return 0;
}
注意:對於GCC或者G++,main()函數的返回值必須是int型,否則可能導致“Compile Error”,即編譯錯誤。
下面是這道題的一個C或者GCC的程序。
#include
int main()
{
int a,b;
scanf("%d %d",&a, &b);
printf("%d\n",a+b);
return 0;
}下面是一個Java的代碼示例,請注意,當提交語言爲Java時,您的類名必須爲Main
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner reader = new Scanner(System.in); int a, b; a = reader.nextInt(); b = reader.nextInt(); System.out.println(a + b); reader.close(); } }
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);
int a, b, c;
a = reader.nextInt();
b = reader.nextInt();
c = a + b;
System.out.println(c);
reader.close();
}
}