A+B for input-output

来源:互联网 发布:flox for mac破解版 编辑:程序博客网 时间:2024/06/05 16:55
  1. 列表内容

Practice (I)

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

#include <stdio.h>int main(){   int a, b;   while( scanf("%d%d",&a,&b) != EOF )   {   printf("%d\n", a + b );    }       return 0;}

Practice (II)

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

#include<stdio.h>int main(){    int a, b, d, i;    while (scanf( "%d", &a) != EOF )    {        for (i = 0; i < a; i ++)        {            scanf( "%d%d", &b, &d );            printf( "%d\n", d+b );        }}}

Practice (III)

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

#include <stdio.h>#include <stdlib.h>int main(){   int a, b;   while( scanf( "%d%d", &a, &b ) != EOF )   {    if( a==0 && b==0 ) break;    printf( "%d\n", a+b );    }       return 0;}

Practice (IV)

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

#include <stdio.h>#include <stdlib.h>int main (){   int i, n, a, sum;   while( scanf( "%d", &n ) !=EOF )   {       if( n == 0) break;       sum = 0;    for( i = 0; i < n; i ++)    {     scanf( "%d",&a );     sum + = a;    }    printf( "%d\n" , sum );    }    return 0;}

Practice (V)

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

#include<stdio.h>int main(){    int n, a, sum, i, j, k;    while ( scanf( "%d" , &n ) != EOF )    {        for ( i = 0; i < n; i ++ )        {            scanf( "%d" , &k );            sum = 0;            for( j = 0; j < k; j ++)            {                scanf( "%d" , &a );                sum + = a;            }        printf( "%d\n" , sum );        }    }    return 0;}

Practice (VI)

Your task is to calculate the sum of some integers.

Input
Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.
Output
For each test case you should output the sum of N integers 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
Sample Output
10
15

#include<stdio.h>int main (){    int n, a, sum, i, j, k;    while ( scanf( "%d" , &k ) != EOF)    {            sum = 0;            for( j = 0; j < k; j ++)            {            scanf( "%d" , &a );            sum + = a;            }        printf( "%d\n" , sum );    }    return 0;}

Practice (VII)

Your task is to Calculate a + b.

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, and followed by a blank line.
Sample Input
1 5
10 20
Sample Output
6

30

#include <stdio.h>int main (){  int a, b, sum;  while( scanf( "%d%d" , &a, &b) != EOF )  {      sum = a + b;      printf( "%d\n" , sum );      printf( "\n" , sum );  }  return 0;}

Practice (VIII)

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 you must note that there is a blank line between outputs.
Sample Input
3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3
Sample Output
10

15

6

#include<stdio.h>int main(){    int n, a, sum, i, j, k;    while ( scanf( "%d" , &n ) != EOF)    {        for (i = 0; i < n; i ++)        {            scanf( "%d" , &k );            sum=0;            for( j = 0; j < k; j ++)            {                scanf( "%d" , &a );                sum+=a;            }        printf("%d\n",sum);        if(i!=n-1) printf("\n");        }     }    return 0;}
原创粉丝点击