| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这怎么也会超时????#include<iostream>
#include<cstring>
#define MAX 1000001
using namespace std;
int main()
{
char s[MAX];
long i,j,n,count,precount=0; //前一个次数,与当前次数比较,求出最大次数
scanf("%s",&s);
while(s[0]!='.')
{
bool flag[MAX]={0}; //
precount=0;
n=strlen(s);
for(i=0;i<n;i++)
{
count=0; //记录当前字母的重复次数
while((flag[i]==1)&&(i<n)) //若已经搜索过,跳过
i++;
if(i==n) //到末尾,跳出循环
break;
for(j=i;j<n;j++)
{
if(s[j]==s[i])
{
count++;
flag[j]=1;
}
}//for j
if(count>precount)
precount=count;
}//for i
cout<<precount<<endl;
scanf("%s",&s);
}//while
return 1;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator