练习基本的输入输出能力:
1.
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
Sample Output
My Code
#include<iostream>
using namespace std;
int main()
{
int a,b;
while(cin>>a>>b)
cout<<a+b<<endl;
return 1;
}
2.
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
Sample Output
6
30
My Code:
#include<iostream>
using namespace std;
int main ()
{
int n,a,b;
cin>>n;
while(n--){
cin>>a>>b;
cout<<a+b<<endl;
}
return 1;
}
3.
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
Sample Output
My Code:
#include<iostream>
using namespace std;
int main()
{
int a,b;
while(cin>>a>>b){
if(a==0 && b==0) break;
cout<<a+b<<endl;
}
return 1;
}
4.
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
Sample Output
#include<iostream>
using namespace std;
int main() {
int n,p,t;
while(1){
cin>>n;
if(n==0) break;
p=0;
while(n--){
cin>>t;
p+=t;
}
cout<<p<<endl;
}
return 1;
}
5.
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
Sample Output
My Code:
#include<iostream>
using namespace std;
int main() {
int n,t,p,x;
cin>>t;
while(t--){
cin>>n;
p=0;
while(n--){
cin>>x;
p+=x;
}
cout<<p<<endl;
}
return 1;
}
6.
Problem 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, 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
Sample Output
My Code:
#include<iostream>
using namespace std;
int main() {
int n,t,p;
while(cin>>n){
p=0;
while(n--){
cin>>t;
p+=t;
}
cout<<p<<endl;
}
return 1;
}