C++ 容器 Vector
来源:互联网 发布:数据魔方什么时候下线 编辑:程序博客网 时间:2024/06/02 04:29
//读入一组整数到vector对象,计算并输出每对相邻组合的和。如果读入元素个数为奇数,则提示用户最后一个元素没有求和,并输出其值。
#include <iostream>
#include <string>#include <vector>
using namespace std;
int main(void)
{
vector<int> int_vec;
int i;
while (cin>>i)
{
int_vec.push_back(i);
}
if(int_vec.size() % 2 == 0)
{
for (vector<int>::size_type index=0; index != int_vec.size(); index=index+2)
{
cout<<"The sum is : "<<int_vec[index] + int_vec[index+1]<<endl;
}
}
else if (int_vec.size() % 2 == 1)
{
for (vector<int>::size_type index=0; index <= int_vec.size()-3; index=index+2)
{
cout<<"The sum is : "<<int_vec[index] + int_vec[index+1]<<endl;
}
vector<int>::size_type index=int_vec.size();
cout<<"The last element is not sumed and its value is : "<<int_vec[index-1]<<endl;
}
system("pause");
return 0;
}
- 【c++】容器vector
- C++-vector(容器)
- 【C++】实现容器Vector
- C++vector(容器)用法
- 【C++】顺序容器 Vector 注意事项
- vector 容器类 (C++)
- C++vector容器用法详解
- C++vector基础容器2.0
- C++STL之vector容器
- C串分隔子串到vector容器内
- C++STL容器技术之Vector
- 初学者学习C++STL之vector容器
- C++STL中vector容器的用法
- 【C++】顺序容器之vector用法
- C++STL中vector容器的用法
- C++STL中vector容器的用法
- C++STL中vector容器的用法
- C模板实现STL容器中的vector
- SWT/JFace开发遇到org.eclipse.core.runtime.IProgressMonitor问题的解决办法
- AndroidManifest.xml中android:configChanges的简介
- java Socket 发送邮件
- 表单提交后,还是停留在本页面的问题
- GridView使用示例(一)
- C++ 容器 Vector
- 改变方式
- 输入n个数,输出比平均值大的数(数组)
- HTML相对路径(Relative Path)和绝对路径(Absolute Path)
- Java_xml_dom4j对xml文件增删读写操作
- 设计模式六大原则(3):依赖倒置原则
- java解析RSS信息
- I Have A Dream !
- .net 如何设置ischecked的值