本篇日誌中寫的是HDU上的若干水題的代碼。ios
1089-1096這幾道題,是用於作輸入-輸出練習用的。spa
HDU1089:給出若干對數字A和B計算兩數和日誌
#include<iostream> using namespace std; int main() { int a, b; while(cin >> a >> b) { cout << a + b << endl; } return 0; }
HDU1090:給出指定對數字A和B計算兩數和code
#include<iostream> using namespace std; int main() { int a, b, times; cin >> times; while(times--) { cin >> a >> b; cout << a + b << endl; } return 0; }
HDU1091:給出若干對數字A和B計算兩數和,輸入兩個0時中止ci
#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 0; }
HDU1092:給出若干組數據,每組數據第一個數字爲該組數據後面的數字數,計算每組數據中第一個數字以後各數字之和,第一個數字爲0時中止input
#include<iostream> using namespace std; int main() { int count, input, sum; while(cin >> count) { if(count == 0) { break; } sum = 0; while(count--) { cin >> input; sum += input; } cout << sum << endl; } return 0; }
HDU1093:給出指定組數據,計算每組數據中數字之和io
#include<iostream> using namespace std; int main() { int counta, countb, input, sum; cin >> counta; while(counta--) { sum = 0; cin >> countb; while(countb--) { cin >> input; sum += input; } cout << sum << endl; } return 0; }
HDU1094:給出若干組數據,每組數據第一個數字爲該組數據後面的數字數,計算每組數據中第一個數字以後各數字之和class
#include<iostream> using namespace std; int main() { int count, input, sum; while(cin >> count) { sum = 0; while(count--) { cin >> input; sum += input; } cout << sum << endl; } return 0; }
HDU1095:給出若干對數,計算每對數字之和,每次輸出中間空1行stream
#include<iostream> using namespace std; int main() { int a, b; while(cin >> a >> b) { cout << a + b << endl << endl; } return 0; }
HDU1096:給出指定組數據,計算每組數據中數字之和,每次輸出中間空一行,最後一次輸出完程序直接結束程序
#include<iostream> using namespace std; int main() { int counta, countb, input, sum; cin >> counta; while(counta--) { sum = 0; cin >> countb; while(countb--) { cin >> input; sum += input; } cout << sum << endl; if(counta != 0) { cout << endl; } } return 0; }
另附兩道簡單的加法題代碼
HDU1000:計算A+B(同1089)
#include<iostream> using namespace std; int main() { int a, b; while(cin >> a >> b) { cout << a + b << endl; } return 0; }
HDU1001:計算1+2+···+n的和
#include<iostream> using namespace std; int main() { int n,i,sum; while(cin >> n) { sum = 0; for(i = 1; i <= n; i++) { sum += i; } cout << sum << endl << endl; } return 0; }
END