exe3.13 suboptimal.cpp

来自「C++ primer 4th edition 部分习题解答 前十章」· C++ 代码 · 共 52 行

CPP
52
字号
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main()
{
	vector <int> vec1,vec2;
	bool isEnd=false;
	for (vector<int>::size_type xi=0;xi!=11;xi++)
	{
		vec1.push_back(xi*10+10);
	}
	
	for (vector<int>::size_type xi=0;xi<=vec1.size();xi+=2)
	{
		if (xi+1==vec1.size())
		{
			cout<<vec1[xi]<<endl<<"That's the end."<<endl;
			isEnd=true;
		}
		else
		{
			cout<<vec1[xi]+vec1[xi+1]<<endl;
		}
	}
	if (!isEnd)
	{
		cout<<"That's the end."<<endl;	
	}
	
	for (vector<int >::size_type xl=0,xr=vec1.size()-1;xl<xr;xl++,xr--)
	{
		if (xl+1==xr)
		{
			cout<<"That's the end."<<endl;
			isEnd=true;
		}
		else
		{
			cout<<vec1[xl]+vec1[xr]<<endl;
		}	
	}
	
	if (!isEnd)
	{
		cout<<"That's the end."<<endl;	
	}
	cout<<vec1.size()<<endl;
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?