| ||||||||||
| 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 | |||||||||
挑灯夜战写的,眼圈都黑了还是wa, 请指点...#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int nStatistic[10]={0,0},m=0,self=0,nLoop=0,nStep=0;
char cLineStart[81],cLine[15][30],cTemp[30];
while (1)
{
cin>>cLineStart;
if (cLineStart[0]=='-') break;
for (int s=0;s<strlen(cLineStart);s++)
nStatistic[cLineStart[s]-'0']++;
for (int i=0;i<15;i++)
{
for (int k=0;k<10;k++)
{
if (nStatistic[k]==0) continue;
else if (nStatistic[k]/10==0)
{
cTemp[m]=nStatistic[k]+'0';
cTemp[m+1]=k+'0';
m+=2;
}
else
{
cTemp[m]=(nStatistic[k]/10)+'0';
cTemp[m+1]=(nStatistic[k]%10)+'0';
cTemp[m+2]=k+'0';
m+=3;
}
}
cTemp[m]='\0';
strcpy(cLine[i],cTemp);
m=0;
for (int e=0;e<10;e++)
nStatistic[e]=0;
for (int s=0;s<strlen(cTemp);s++)
nStatistic[cTemp[s]-'0']++;
if (strcmp(cTemp,cLineStart)==0)
{nStep=nLoop=i+1;self=1;goto Loop;}
else
{
for (int j=0;j<i;j++)
if (strcmp(cTemp,cLine[j])==0)
{
nStep=i+1;
nLoop=i-j;
goto Loop;
}
}
}
cout<<cLineStart<<" can not be classified after 15 iterations "<<endl;
Loop:
if (self)
{
if (nStep==1)
cout<<cLineStart<<" is self-inventorying "<<endl;
else
cout<<cLineStart<<" enters an inventory loop of length "<<nLoop<<endl;
}
else if (nLoop==1)
cout<<cLineStart<<" is self-inventorying after "<<nStep-1<<" steps "<<endl;
else
cout<<cLineStart<<" enters an inventory loop of length "<<nLoop<<endl;
nStep=nLoop=self=0;
for (int e=0;e<10;e++)
nStatistic[e]=0;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator