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:看我的行吗?219MS

Posted by gaoshan at 2009-08-19 10:17:19 on Problem 3438
In Reply To:Accepts了,但是花的时间很多,请问如何优化? Posted by:xiaohao2009 at 2009-04-28 18:09:23
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
	int n,t,i,count;
	cin>>n;
	char a[10000],p;
	while(n--)
	{
        cin>>a;
		t=strlen(a);
		for(i=0;i<t;i++)
		{
			 if(a[i]!=a[i+1])
				 cout<<"1"<<a[i];
			 else
			 {
				 if(i==t)
					 break;
				 count=1;
                 while(a[i]==a[i+1])
				 {   
				     p=a[i];
                     count++;
				     i++;
				 }
				 cout<<count<<p;
			 }
		}
        cout<<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