ACM/ICPC ZOJ1016-Parencodings解题方法代码

#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int testcase_num;
	cin >> testcase_num;
	vector<int> *result = new vector<int>[testcase_num];
	for ( int i = 0; i < testcase_num; i++ )
	{
		int number_transfered;
		cin >> number_transfered;
		vector<int> transfered;
		int count = 0;
		int input;
		while( count < number_transfered && cin >> input )
		{
			transfered.push_back(input);
			count++;
		}
		vector<int>::iterator trans_iter = transfered.begin();
		vector<int> p_seq;
		count = 0;
		while( trans_iter != transfered.end() )
		{
			if ( count != *trans_iter)
			{
				p_seq.push_back(0);
				count++;
			}
			
			if ( count == *trans_iter )
			{
				p_seq.push_back(1);
				trans_iter++;
			}
			
		}

		//vector<int> w_seq;
		for ( vector<int>::iterator p_iter = p_seq.begin(); p_iter != p_seq.end(); p_iter++ )
		{
			if ( *p_iter == 1 )
			{
				vector<int>::iterator temp = p_iter;
				int count_num = 1;
				while( *temp != 0 )
				{
					if ( *temp == -1 )
					{
						count_num++;
					}
					temp--;
					if ( *temp == 0 )
					{
						*temp = -1;
						break;
					}
				}

				result[i].push_back(count_num);
			}
		}

		
	}
	for ( int i = 0; i < testcase_num; i++ )
	{
		for ( vector<int>::iterator iter = result[i].begin(); iter < result[i].end(); iter++ )
		{
			if (iter != result[i].end() - 1)
			{
				cout << *iter <<" ";
			}
			else
				cout << *iter;
		}
		cout << endl;
	}
	
	return 0;
}

 

posted @ 2013-06-12 10:23  2011winseu  阅读(276)  评论(0编辑  收藏  举报