您的位置:首页 > 编程语言

笔试编程题输入输出模板备忘

2017-03-27 10:35 141 查看
A+B Problem描述Given two integers a and b, calculate their sum a + b.输入The input contains several test cases. Each contains a line of two integers, a and b.输出For each test case output a+b on a seperate line.样例输入
1 2
3 4
5 6
样例输出
3
7
11
语言样例程序
C
#include <stdio.h>

int main(void) {
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(void) {
int a, b;
while(cin >> a >> b) {
cout << a + b << endl;
}
return 0;
}
Java
import java.util.Scanner;

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

public class AplusB
{
private static void Main()
{
string line;
while((line = Console.ReadLine()) != null)
{
string[] tokens = line.Split(' ');
Console.WriteLine(int.Parse(tokens[0]) + int.Parse(tokens[1]));
}
}
}
Python2
while True:
try:
(x, y) = (int(x) for x in raw_input().split())
print x + y
except EOFError:
break
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  编程