ACM總結之 A+B problem 總結

nyoj    A+B problemthis

時間限制:3000 ms  |  內存限制:65535 KB
難度:0
 
描述
此題爲練手用題,請你們計算一下a+b的值
 
輸入
輸入兩個數,a,b
輸出
輸出a+b的值
樣例輸入
2 3樣例輸出
5spa

 

代碼:
#include <stdio.h>ip

int main()內存

 { int a,b;ci

while(scanf("%d%d",&a,&b)!=EOF);
printf("%d",a+b);input

return 0;
}    it

 

hdu1000io

A + B ProblemTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)class


Total Submission(s): 317452    Accepted Submission(s): 92274test

 

 

 


Problem Description
Calculate A + B.
 
Input
Each line will contain two integers A and B. Process to end of file.
 
Output
For each case, output A + B in one line.
 
Sample Input
1 1
 
Sample Output
2
 
Author
HDOJ
代碼:


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

 

 

hdu 1001
Sum Problem
Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 221055    Accepted Submission(s): 54049

 

 

Problem Description
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).

In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
 
Input
The input will consist of a series of integers n, one integer per line.
 
Output
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
 
Sample Input
1 100
 
Sample Output
1 5050
 
Author
DOOM III
 
代碼:
#include<stdio.h>
int main()
{int a,b,sum=0;
while(scanf("%d",&b)!=EOF)
{sum=0;
for(a=1;a<=b;a++)
{
sum=sum+a;
}

printf("%d\n\n",sum);
}
return 0;
}
hdu 1089
A+B for Input-Output Practice (I)
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 62478    Accepted Submission(s): 35144


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
 
代碼:
#include <stdio.h>
int main()
{int a,b;
    while(scanf("%d %d",&a,&b)!=EOF)
    printf("%d\n",a+b);
    return 0;
}
 
hdu 1090

A+B for Input-Output Practice (II)
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 47298    Accepted Submission(s): 31464

 

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
 
代碼:
#include <stdio.h>
int main()
{int a,b,c,m=1;
    scanf("%d",&c);
    while(scanf("%d %d",&a,&b)!=EOF)
    if(m<=c)
    {
    printf("%d\n",a+b);
    m++;
    }
    return 0;
}

hdu 1091
A+B for Input-Output Practice (III)
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 56525    Accepted Submission(s): 29033

 

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 <stdio.h>
int main()
{int a,b;
    while(scanf("%d%d",&a,&b)&&a!=0||b!=0)
    printf("%d\n",a+b);
    return 0;
    }

hdu 1092
A+B for Input-Output Practice (IV)
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 50203    Accepted Submission(s): 26934

 

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
代碼:
#include "stdio.h"
int a[100];
int main()
{int i,n;
    int sum(int x);
    while(scanf("%d",&n)&&n!=0)
    {for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    printf("%d\n",sum(n));
    }
    return 0;
}
int sum(int x)
{int c=0,y;
    for(y=0;y<x;y++)
    c=c+a[y];
    return (c);
}


hdu 1093
A+B for Input-Output Practice (V)
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 36626    Accepted Submission(s): 24922

 

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

4 1 2 3 4
5 1 2 3 4 5
 


Sample Output
10
15
 


Author
lcy
代碼:
#include "stdio.h"
#define P 1000
int a[P];
int main()
{int i,n,m,s=0;
scanf("%d",&n);
while(n--)
{scanf("%d",&m);
for(i=0;i<m;i++)
{scanf("%d",&a[i]);
s=s+a[i];
}
printf("%d\n",s);
s=0;
}
return 0;
}

 通常來講,A+B problems 只是簡單題,練習基本的輸入輸出而已,通常有三種格式:

一: 輸入不說明有多少個Input Block,以EOF爲結束標誌

#include <stdio.h>

 int main()

 {
    int a,b;
    while(scanf("%d %d",&a, &b) != EOF)      printf("%d\n",a+b);
 }
 二: 輸入一開始就會說有N個Input Block,下面接着是N個Input Block。
 
#include <stdio.h>
 int main()
 {
    int n,i,a,b;
 scanf("%d",&n);
for(i=0;i<n;i++)
{
   scanf("%d %d",&a, &b);
    printf("%d\n",a+b);
 }
 }
或者是:
#incldue "stdio.h"
int main()
{int a,b,n;
scanf("%d",&n);
while(n--)
{scanf("%d%d",&a,&b);
{.........
}
}
}
三: 輸入不說明有多少個Input Block,但以某個特殊輸入爲結束標誌。
以輸入0 0 爲結束標誌爲例以下:
 
#include <stdio.h>
 int main()
 {
int a,b;
while(scanf("%d %d",&a, &b) &&(a!=0 || b!=0))
    printf("%d\n",a+b);
 }
相關文章
相關標籤/搜索