4-a+b问题

xiaoxiao2021-02-28  52

问题:

输入两个整数a,b,输出两个整数的和。

输入格式

第一行输入一个整数T,表示需要计算的次数。

接下来T 行,每行输入两个用空格分隔的整数a,b

输出格式

对于每次输入的a,b,输出a+b 的值。结果保证在32 位整型(int)范围内。

样例输入

5 1 2 3 4 5 6 7 8 9 10

样例输出

3 7 11 15 19

代码解答:

#include <iostream> #include <vector> //STL动态数组 using namespace std; int main() { int a,b; int n; vector<int> all; //计算和 cin>>n; for(int i=0;i<n;i++){ cin>>a>>b; all.push_back(a+b);//相当于压入数组 } vector<int>::iterator it; //创建迭代器以访问该动态数组 for(it=all.begin();it!=all.end();it++){ //注意all.end()指向的是最后一个元素的下一个位置,所以能访问到最后一个元素 cout<<*it<<endl;//输出值 } return 0; }

转载请注明原文地址: https://www.6miu.com/read-2625792.html

最新回复(0)