题目1000: A + B Problem
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int a, b;
while(scanf("%d %d",&a, &b)!=EOF){
cout<<a+b<<endl;
}
cout << "Hello world!" << endl;
return 0;
}
题目1001:Sum Problem
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int a, b;
//freopen("test.txt","r",stdin);
while(scanf("%d",&a)!=EOF){
if(a%2==0){
b = a/2;
cout<<b*(a+1)<<endl<<endl;
}
else{
b = (a+1)/2;
cout<<b*a<<endl<<endl;
}
}
return 0;
}
注:不可以直接用a*(a+1)/2,因为a*(a+1)可能会超过32位。