#include <stdlib.h>
#include<fstream>
using namespace std;
char *itoa(int num, char *str, int radix)
{
//0的情况
if (num==0)
{
str[0]='0';
str[1]='\0';
return str;
}
char string[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char* ptr = str;
int i;
int j;
while (num)
{
*ptr++ = string[num % radix];
num /= radix;
if (num < radix)
{
*ptr++ = string[num];
*ptr = '\0';
break;
}
}
//两边对调
j = ptr - str - 1;
for (i = 0; i < (ptr - str) / 2; i++)
{
int temp = str[i];
str[i] = str[j];
str[j--] = temp;
}
return str;
}
int atoi(char *s)
{
char *p = s;
char c;
int i = 0;
while(c=*p++)
{
if(c>='0' && c<='9')
{
i = i*10 + (c-'0');
}
else
return -1; //Invalid string
}
return i;
}
int main()
{
ifstream fin ("runround.in");
ofstream fout ("runround.out");
int n,i,j,k,a;
fin>>n;
n++;
while(true)
{
char st[30];
string s=itoa(n,st,10);
//判断是否含有‘0’
for(i=0;i<s.length();i++)
{
if(s[i]=='0')
break;
}
if(i<s.length())
{
n++;
continue;
}
//判断是否有重复字符
bool same=false;
for(i=0;i<s.length();i++)
{
for(j=i+1;j<s.length();j++)
{
if(s[i]==s[j])
{
same=true;
break;
}
}
if(j<s.length())
break;
}
if(same)
{
n++;
continue;
}
char bs[30]={false};
i=0;
j=0;
k=0;
char c[2];
while(k<s.length()-1)
{
c[0]=s[i];
c[1]='\0';
a=atoi(c);
int pos=(a+j)%s.length();
j=pos;
i=pos;
k++;
bs[pos]=true;
}
c[0]=s[i];
c[1]='\0';
a=atoi(c);
int pos=(a+j)%s.length();
if(pos==0)
{
for(i=1;i<s.length();i++)
{
if(!bs[i])
{
break;
}
}
if(i==s.length())
{
fout<<n<<endl;
return 0;
}
}
n++;
}
return 0;
}
Runaround Numbers
最新推荐文章于 2019-06-25 00:39:44 发布