阅读背景:

C++ Primer 习题 4.34

来源:互联网 
 
 
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
		
using namespace std;

int main()
{
	string value;
	vector<string> vs;
	while (cin >> value)
		vs.push_back(value);
	int d_x = 0, d_y;
	d_y = vs.size();
	int di[d_y];
	char *p[d_y];
	for (vector<string>::iterator iter = vs.begin(); iter != vs.end(); ++iter)
	{
		string ts = *iter;
		const char *str = ts.c_str();
		int dimension = ts.size() + 1;
		di[d_x] = ts.size();
		p[d_x] = new char[dimension];
		for (int i = 0; i < dimension; ++i)
		{
			*p[d_x] = *str;
			++p[d_x];
			++str;
		}
		++d_x;
	}
	cout << *(p[d_x - 1] - 2) << endl;
	cout << *(p[d_x - 2] - 2) << endl;
	for (int i = 0; i < d_y; ++i)
	{
		char *pt = p[i] - di[i] - 1;
		while (*pt)
		{
			cout << *pt;
			++pt;
		}
		cout << "\n";
		delete [] p[i];
	}
	return 0;
}#include <iostream>
#include <vector>
#inclu



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: