usaco-2.2-runaround-pass

这个题意,呵呵,要理解清楚:

/*
ID: qq104801
LANG: C++
TASK: runround
*/

#include <iostream>
#include <fstream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <algorithm>

using namespace std;

int n;

void numtostr(int x,char *s)
{
    int i=0;    
    while(x)
    {        
        s[i++]=x%10+'0';
        x/=10;
    }
    s[i]='';
    int j=i-1;
    i=0;
    while(i<j)swap(s[i++],s[j--]);
}

bool judge(int x)
{
    int len,i,p;
    char str[10];
    bool visited[10];
    numtostr(x,str);
    len=strlen(str);
    memset(visited,false,sizeof(visited));
    p=0;
    while (!visited[p])
    {
        visited[p]=true;
        p=(p+str[p]-'0')%len;        
    }
    if(p) return false;
    for(i=0;i<len;i++)
        if(!visited[i]) return false;
    sort(str,str+len);
    for(i=0;i<len-1;i++)
        if(str[i]==str[i+1])return false;
    return true;
}


void test()
{    
    freopen("runround.in","r",stdin);
    freopen("runround.out","w",stdout);
    cin>>n;
    int i;
    for(i=n+1;!judge(i);i++);
    cout<<i<<endl; 
}

int main () 
{        
    test();        
    return 0;
}

test data:

USER: cn tom [qq104801]
TASK: runround
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.008 secs, 3376 KB]
   Test 2: TEST OK [0.022 secs, 3376 KB]
   Test 3: TEST OK [0.005 secs, 3376 KB]
   Test 4: TEST OK [0.008 secs, 3376 KB]
   Test 5: TEST OK [0.068 secs, 3376 KB]
   Test 6: TEST OK [0.016 secs, 3376 KB]
   Test 7: TEST OK [0.086 secs, 3376 KB]

All tests OK.

Your program ('runround') produced all correct answers! This is your submission #2 for this problem. Congratulations!

Here are the test data inputs:

------- test 1 ----
99
------- test 2 ----
111110
------- test 3 ----
134259
------- test 4 ----
348761
------- test 5 ----
1000000
------- test 6 ----
5000000
------- test 7 ----
9000000

Keep up the good work!
Thanks for your submission!
/***********************************************

看书看原版,原汁原味。

不会英文?没关系,硬着头皮看下去慢慢熟练,才会有真正收获。

没有原书,也要网上找PDF来看。

网上的原版资料多了去了,下载东西也到原始下载点去看看。

你会知其所以然,呵呵。

***********************************************/

原文地址:https://www.cnblogs.com/dpblue/p/3955922.html