HDOJ of a + b issue summary

Copyright: from: Jihome https://blog.csdn.net/jihome/article/details/88955986

HUOJ of a + b is the main problem then solve the problem input and output formats, provide the basis to the back of the AC, in order to prepare the Blue Bridge Cup national tournament it, I was ready to brush the question, and I hope to make progress, the following is a + b summary of the problem, it is water.

Summary: learn C ++ input to the end of the file how to deal with: cin.eof () function is to determine whether the end of file in C is directly judge whether equal eof.

1089

#include <iostream>
using namespace std;
int main(){
	int a,b;
	while(cin>>a>>b,!cin.eof()){
		cout<<a+b<<endl;
	}
	return 0;
} 

//1090

#include <iostream>
using namespace std;
int main(){
	int a,b,n;
	cin>>n;
	while(n--){
		cin>>a>>b;
		cout<<a+b<<endl;
	}
	return 0;
} 

//1091

#include <iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	while(a!=0||b!=0){		
		cout<<a+b<<endl;
		cin>>a>>b;
	}
	return 0;
}

//1092

#include <iostream>
using namespace std; 
int main(){
	int n,x;
	int i,sum=0;
	cin>>n;
	while(n!=0){
		for(i=0;i<n;i++){
			cin>>x;
			sum+=x;
		}
		cout<<sum<<endl;
		sum=0;
		cin>>n;
	}
	return 0;
}

//1093

#include <iostream>
using namespace std; 
int main(){
	int n,x,N;
	int i,j,sum=0;
	cin>>N;
	for(j=0;j<N;j++){
		cin>>n;
		for(i=0;i<n;i++){
			cin>>x;
			sum+=x;
		}
		cout<<sum<<endl;
		sum=0;
	}
	return 0;
}

//1094

#include <iostream>
using namespace std; 
int main(){
	int n,x;
	int i,sum=0;
	while(cin>>n,!cin.eof()){
		for(i=0;i<n;i++){
			cin>>x;
			sum+=x;
		}
		cout<<sum<<endl;
		sum=0;
	}
	return 0;
}

//1095

#include <iostream>
using namespace std;
int main(){
	int a,b;
	while(cin>>a>>b,!cin.eof()){
		cout<<a+b<<endl<<endl;
	}
	return 0;
} 

// 1096
this question to determine the final note of a number, the last number is not to have two line breaks.

#include <iostream>
using namespace std; 
int main(){
	int n,x,N;
	int i,j,sum=0;
	cin>>N;
	for(j=0;j<N;j++){
		cin>>n;
		for(i=0;i<n;i++){
			cin>>x;
			sum+=x;
		}
		cout<<sum<<endl;
		sum=0;
		if(j!=N-1)
			cout<<endl;
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/jihome/article/details/88955986