| ||||||||||
| 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<string>
#include <algorithm>
using namespace std;
int isequel(char c[],int b[],int len)
{
for(int i=0;i<len;i++)
{
if(b[i]!=c[i]-48)
return 0;
}
return 1;
}
void main()
{
char c[61];
int t[61];
while(cin>>c)
{
int len=strlen(c);
int a[61];
for(int i=0;i<len;i++)
{
t[i]=c[i]-48;
a[i]=t[i];
}
sort(c,c+len);
int k=1;
for(;k<len;k++)
{
int b[61]={0};
for(int j=len-1;j>=0;j--)
{
int temp=a[j]+t[j];
// if(j>=0)
// temp+=b[j];
// cout<<temp<<endl;
b[j]+=temp%10;
b[j-1]=temp/10;
if(b[j]>9)
{
b[j-1]+=b[j]/10;
b[j]=b[j]%10;
}
t[j]=b[j];
}
// for(int v=0;v<len;v++)
// cout<<t[v];
// cout<<endl;
sort(b,b+len);
if(!isequel(c,b,len))
{
break;
}
}
if(k==len)
{
for(int r=0;r<len;r++)
cout<<a[r];
cout<<" is cyclic"<<endl;
}
else
{
for(int r=0;r<len;r++)
cout<<a[r];
cout<<" is not cyclic"<<endl;
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator