//读一组数到vector对象,计算收尾配对元素的和并输出
#include <iostream>
#include <vector>
int main()
{
std::vector<int> ivec;
int temp, add;
while(std::cin>>temp)
ivec.push_back(temp);
typedef std::vector<int>::size_type vec_type;
vec_type flag;
for(vec_type ix=0; ix<(ivec.size()/2); ++ix)
{
add = ivec[ix] + ivec[ivec.size()-ix-1];
std::cout << add << "\t";
if((ix+1)%6==0)
std::cout << std::endl;
flag=ix;
}
if(ivec.size()%2 != 0)
std::cout << std::endl
<< "The middle element do not add,it's: "
<< ivec[flag]
<< std::endl;
return 0;
}
C++ Primer第四版习题--3.13
最新推荐文章于 2023-12-26 08:31:48 发布