Advertisement
mickypinata

USACO-T028: Runaround Numbers

Dec 1st, 2021
571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. /*
  2. ID: mickyta1
  3. TASK: runround
  4. LANG: C++
  5. */
  6.  
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9.  
  10. typedef unsigned int uint;
  11.  
  12. const int N = 9 + 5;
  13.  
  14. bool visited[N];
  15.  
  16. int main(){
  17.     freopen("runround.in", "r", stdin);
  18.     freopen("runround.out", "w", stdout);
  19.  
  20.     int lwb;
  21.     scanf("%d", &lwb);
  22.     for(uint i = lwb + 1; true; ++i){
  23.         string str = to_string(i);
  24.         for(int j = 0; j <= 9; ++j){
  25.             visited[j] = false;
  26.         }
  27.         bool hasDup = false;
  28.         for(int j = 0; j < str.size(); ++j){
  29.             int c = str[j] - '0';
  30.             if(visited[c]){
  31.                 hasDup = true;
  32.                 break;
  33.             }
  34.             visited[c] = true;
  35.         }
  36.         if(hasDup || visited[0]){
  37.             continue;
  38.         }
  39.         for(int j = 0; j <= 9; ++j){
  40.             visited[j] = false;
  41.         }
  42.         hasDup = false;
  43.         int mve = 0;
  44.         for(int j = 0; j < str.size(); ++j){
  45.             int c = str[mve % str.size()] - '0';
  46.             if(visited[c]){
  47.                 hasDup = true;
  48.                 break;
  49.             }
  50.             visited[c] = true;
  51.             mve += c;
  52.         }
  53.         if(hasDup || str[mve % str.size()] != str[0]){
  54.             continue;
  55.         }
  56.         cout << str << '\n';
  57.         break;
  58.     }
  59.  
  60.     fclose(stdin);
  61.     fclose(stdout);
  62.     return 0;
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement