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

这题折腾死我了,为啥用string总是TLE呢。60题刷水被呛了

Posted by 1004101213 at 2012-02-22 12:38:10 on Problem 1750
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
char a[100005][20];
int kik(int k)
{
    int i,ans(0);
    for(i=0;i<strlen(a[k])&&i<strlen(a[k-1]);i++)
     {
         if(a[k][i]==a[k-1][i])
     {
         ans++;
     }
         else break;
     }//cout<<ans<<endl;
     return ans;

}
int main()
{


    int p(0),i(0),j;
    while(gets(a[i]))
    {

        if(i>0)
            {
            if(a[i][0]==a[i-1][0])
            {

            if(p>=kik(i))
              p=kik(i);
            else p++;
            }
            else p=0;

            }

        for(j=0;j<p;j++)printf(" ");
        printf("%s\n",a[i]);

      i++;
    }


 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