Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪位给个快点的方法啊.. 我居然3000多ms, 太丢脸了. 话说本人很懒,用stl了.

Posted by lijinwu at 2010-04-12 18:01:20 on Problem 3438
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main()
{
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	int n;
	string str;
	string res;
	scanf("%d",&n);
	while(n--)
	{
		cin >> str;
		res.clear();
		int index=0;
		int count=1;
		for(int i=1;i!=str.size()+1;++i)
		{
			if(str[i]!=str[index])
			{
				stringstream s;
				string ss;
				s << count;
				s >> ss;
				res+=ss+str[index];
				index=i;
				count=1;
			}
			else
			{
				count++;
			}
		}
		cout << res << endl;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator