Advertisement
Hippskill

Untitled

Jan 28th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include<stdio.h>
  3. #include<iostream>
  4. #include<vector>
  5. #include<cmath>
  6. #include<algorithm>
  7. #include<map>
  8. #include<set>
  9. #include<sstream>
  10. #include<cstring>
  11. #include<numeric>
  12. #include<limits.h>
  13. #include<time.h>
  14. using namespace std;
  15.  
  16.  
  17. vector<int> str;
  18.  
  19.  
  20. set<int> was;
  21.  
  22. int getLast() {
  23.     int res = 0;
  24.     for (int i = str.size() - 4; i < str.size(); i++) {
  25.         res *= 10;
  26.         res += str[i];
  27.     }
  28.     return res;
  29. }
  30.  
  31. int main() {
  32. #ifndef ONLINE_JUDGE
  33.     freopen("input.txt", "r", stdin);
  34. #endif
  35.  
  36.     freopen("output.txt", "w", stdout);
  37.  
  38.     srand(time(0));
  39.     for (int i = 0; i < 4; i++) {
  40.         str.push_back(rand() % 10);
  41.     }
  42.    
  43.     was.insert(getLast());
  44.    
  45.     while (was.size() != 10000) {
  46.         bool ok = false;
  47.         for (int i = 0; i < 10; i++) {
  48.             str.push_back(i);
  49.             int val = getLast();
  50.             if (was.count(val) != 0) {
  51.                 str.pop_back();
  52.             }
  53.             else {
  54.                 ok = true; 
  55.                 break;
  56.             }
  57.         }
  58.         if (!ok) {
  59.             str.push_back(rand() % 10);
  60.         }
  61.     }
  62.  
  63.     printf("%d\n", str.size());
  64.     for (auto i : str) {
  65.         printf("%d", str[i]);
  66.     }
  67.  
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement