A+B 三连

刚入门的时候肯定都要做一些简单的题目,一是为了适应,二是为了增强信心。

A+B(一)

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 215  Solved: 143

Description

求两个整数的和并输出

Input

第一行输入一个整数n(1 <= n <= 100)
接着输入n组数,每组两个整数

Output

输出每组整数的和并输出

Sample Input

1
1 3
2
2 5
11 22

Sample Output

4
7
33



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




A+B(二)

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 200  Solved: 130

Description

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(1 <= N <= 10000), and then N integers Ai( |Ai| <= 10000) 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 <iostream>
using namespace std;
int main()
{
  int n,i,a,b;
  while(scanf("%d",&n)==1)   
  {
  a = 0;
  for(i=0;i<n;i++)
  {
    scanf("%d",&b);
    a=a+b;    
  }
printf("%d\n",a);   
  }
  return 0;
}




A+B (三)

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 117  Solved: 79

Description

Your task is to calculate the sum of some integers. 

Input

Input contains an integer N(0 < N <= 100) in the first line, and then N lines follow. Each line starts with a integer M, and then M(0 < M <= 100) 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 a, i ,m;
    while(~scanf("%d",&m))
    {
        int b;
        for(i=0;i<m;i++)
        {
            int sum=0;
            int il;
            scanf("%d",&a);
            for(il=1;il<=a;il++)
            {
                scanf("%d",&b);
                sum=sum+b;
            }
            printf("%d\n",sum);
        }
    }
    return 0;
}

阅读更多

没有更多推荐了,返回首页