64,637
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector< int > temp;
int word;
while(cin>>word)
{
temp.push_back(word);
}
cin.clear();
/***********判断输入是否为空******************/
if(temp.size() == 0)
{
cout << "NO DATA INPUT!" <<endl;
return -1;
}
vector< int >::size_type first=0,last = temp.size()-1;
/***********首尾数据相加**********************/
for(;first<last;++first,--last)
{
cout<<temp[first] + temp[last]<<endl;
}
/************考虑奇数个vector< int > 对象************/
if(first == last)
{
cout<<endl
<<"The center element is not been summed"
<<"and its value is:"
<<temp[first]<<endl;
}
return 0;
}