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

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

Posted by lulyon at 2011-05-15 16:08:16 on Problem 3438 and last updated at 2011-05-15 16:09:08
In Reply To:哪位给个快点的方法啊.. 我居然3000多ms, 太丢脸了. 话说本人很懒,用stl了. Posted by:lijinwu at 2010-04-12 18:01:20
> #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;
> }

str.size() 不要写到循环里面。

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