您的位置:首页 > 其它

Runaround Numbers chapter 2.2

2013-08-30 18:00 232 查看
题目看懂了到是不难,直接枚举,不过调错真是调了好久,提交了12次才过啊啊啊啊啊

/*

ID: hubiao cave

PROG: runround

LANG: C++

*/

#include<iostream>

#include<fstream>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

int main()

{

ifstream fin("runround.in");
ofstream fout("runround.out");

int used[11]={0};
int start;
char buf[20]={0};
fin>>start;
int i=start;

while(1)
{
memset(buf,0,20);
memset(used,0,sizeof(int)*11);

++i;
//_itoa(i,buf,10);
sprintf(buf,"%d",i);
string str=buf;
if(str.find('0')!=-1)
continue;
int m=i;

int flag=0;
while(m/10>=1)
{
if(used[m%10])
{
flag=1;
break;
}
else
{

used[m%10]=1;
m/=10;
}
}
if(flag)
continue;
if(used[m])
continue;
else
{
memset(used,0,sizeof(int)*11);

int count=0;
int sta=0;
int starnum=str[0]-'0';
int flag=0;
while(count<str.size()-1)
{

sta=sta+(str[sta]-'0')%str.size();
if(sta>=str.size())
sta%=str.size();
if(used[str[sta]-'0']||sta==0)
{
flag=1;
break;
}
else
{
used[str[sta]-'0']=1;
}
count++;
}

if(flag)
continue;
sta=sta+(str[sta]-'0')%str.size();
if(sta>=str.size())
sta%=str.size();
if(sta==0)
{
fout<<i<<endl;
break;
}
}

}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: