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

Accepts了,但是花的时间很多,请问如何优化?

Posted by xiaohao2009 at 2009-04-28 18:09:23 on Problem 3438
这条是水题,Accepts了,但是却花了641MS,感觉好多啊,请问如何优化?完整代码如下:
#include<iostream>
#include<string>
using namespace std;

int main()
{
    int n,i,j,k,flag,m;
    string str;
    cin>>n;
    for(k=0;k<n;k++)
    {
                    cin>>str;
                    for(j=0;j<str.size();j=m)
                    {
                                             i=j+1;
                                             flag=1;
                                             for(i=j+1,flag=1;str[i]==str[j];i++)
                                             flag++;
                                             m=i;
                                             cout<<flag<<str[j];
                    }
                    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