# 向量加法 https://neoj.sprout.tw/problem/442/ ### 題目敘述 你受夠了各種題敘長得要命的數學和程式作業了。 讓我們回到最簡單的數學:加法(向量版) 把兩個整數向量相加就對了 ### 輸入 輸入有兩行數字$x_1,x_2,x_3\ ......x_n$,數字間以空格分隔。 $x_i$為整數且$0≤x_i<10^9$ ### 輸出 輸出兩向量相加的結果,行尾不要有多餘空格 ### 範例輸入輸出 #### 範例輸入 I ``` 1 2 3 4 5 6 7 8 ``` #### 範例輸出 I ``` 6 8 10 12 ``` #### 範例輸入 II ``` 12 34 56 65 43 21 ``` #### 範例輸出 II ``` 77 77 77 ``` ### Hint 要讀一整行字可以用 ```cpp std::getline(std::cin, my_string) //讀一行到 my_string ``` # Code ```cpp #include <iostream> #include <string> #include <sstream> using namespace std; int in1[1005], in2[1005]; int main() { string s1, s2; stringstream ss1, ss2; getline(cin, s1); getline(cin, s2); ss1 << s1; ss2 << s2; int a = 0, b = 0; while (ss1 >> in1[a++]) {} while (ss2 >> in2[b++]) {} a--; for (int i = 0; i < a; i++) { cout << in1[i] + in2[i] << " \n"[i == a - 1]; } } ```