输入格式:有多个 case 输入,直到文件结束
C 语言多组数据输入
输出格式:一行一个结果
Problem Description
Your task is to Calculate a + b.
Too easy?! Of course! I specially designed the problem for acm beginners.
You must have found that some problems have the same titles with this one, yes, all these
problems were designed for the same aim.
Input
The input will consist of a series of pairs of integers a and b, separated by a space, one
pair of integers per line.
Output
For each pair of input integers a and b you should output the sum of a and b in one line,
and with one line of output for each line in input.
Sample Input
1 5
10 20
Sample Output
6
30
Author
lcy
Recommend
JGShining
#include
int main()
{
}
int a,b;
while( scanf( "%d%d" , &a , &b ) != EOF )
//输入直到文件结尾
{
}
printf( "%d\n" , a+b );
//一行一个结果
return 0;
HDOJ1090
输入格式:先输入有 case 数,再依次输入每个 case
输出格式:一行一个结果
#include
Problem Description
Your task is to Calculate a + b.
Input
Input contains an integer N in the first line, and then N lines follow. Each line consists of a
pair of integers a and b, separated by a space, one pair of integers per line.
Output
For each pair of input integers a and b you should output the sum of a and b in one line,
and with one line of output for each line in input.
Sample Input
2
1 5
10 20
Sample Output
6
30
Author
lcy
Recommend
JGShining
int main()
{
int n,a,b;
scanf( "%d" , &n );
//输入的 case 数
while( n-- )
//控制输入
scanf( "%d%d" , &a , &b );
printf( "%d\n" , a+b );
//一行一个结果
{
}
return 0;
}
HDOJ1091
输入格式:每行输入一组 case,当 case 中的数据满足某种情况时退出
输出格式:一行一个结果
Problem Description
Your task is to Calculate a + b.
Input
Input contains multiple test cases. Each test case contains a pair of integers a and b, one
pair of integers per line. A test case containing 0 0 terminates the input and this test case
is not to be processed.
Output
For each pair of input integers a and b you should output the sum of a and b in one line,
and with one line of output for each line in input.
Sample Input
1 5
10 20
0 0
Sample Output
6
30
Author
lcy
Recommend
JGShining
#include
int main()
{
}
int a,b;
while( scanf( "%d%d" , &a , &b ) && (a||b) )
//输入直到满足 a 和 b 均为0结束
{
}
printf( "%d\n" , a+b );
//一行一个结果
return 0;
HDOJ1092
输入格式:每组 case 前有一个控制输入个数的数,当这个数为0结束
输出格式:一行一个结果
#include
Problem Description
Your task is to Calculate the sum of some integers.
Input
Input contains multiple test cases. Each test case contains a integer N, and then N
integers follow in the same line. A test case starting with 0 terminates the input and this
test case is not to be processed.
Output
For each group of input integers you should output their sum in one line, and with one line
of output for each line in input.
Sample Input
4 1 2 3 4
5 1 2 3 4 5
0
Sample Output
10
15
Author
lcy
Recommend
JGShining
int main()
{
int n,sum;
while( scanf( "%d" , &n ) && n ) //每组 case 前有一个控制该组输入数据的数,为0结束
{
}
int x;
sum = 0;
while( n-- )
//控制该组输入个数
{
}
scanf( "%d" , &x );
sum += x;
printf( "%d\n" , sum );
//一行一个结果
return 0;
}
HDOJ1093
输入格式:一开始有一个控制总的输入 case 的数,而每个 case 中又有一个控制该组输入
数据的数
输出格式:一行一个结果
Problem Description
Your task is to calculate the sum of some integers.
Input
Input contains an integer N in the first line, and then N lines follow. Each line starts with a
integer M, and then M integers follow in the same line.
Output
For each group of input integers you should output their sum in one line, and with one line
of output for each line in input.
Sample Input
2
4 1 2 3 4
5 1 2 3 4 5
Sample Output
10
15
Author
lcy
5