Advertisement
Hippskill

Untitled

Jan 27th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 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. using namespace std;
  14.  
  15.  
  16. set<int> to;
  17.  
  18.  
  19. void found(string cur) {
  20.     to.erase(cur[cur.length() - 1] - '0');
  21.     for (int i = cur.length() - 4; i < cur.length(); i++) {
  22.         for (int len = 1; len <= cur.length() - i; len++) {
  23.             int toDel = 0;
  24.             for (int j = 0; j < len; j++) {
  25.                 toDel *= 10;
  26.                 toDel += cur[i + j] - '0';
  27.             }
  28.             to.erase(toDel);
  29.         }
  30.     }
  31. }
  32.  
  33.  
  34. int res = LONG_MAX;
  35. void solve() {
  36.     for (int i = 0; i <= 9999; i++) {
  37.         to.insert(i);
  38.     }
  39.  
  40.     string cur = "";
  41.     for (int i = 0; i < 4; i++) {
  42.         cur += rand() % 10 + '0';
  43.         to.erase(cur[i] - '0');
  44.     }
  45.     found(cur);
  46.     while (to.size() != 0) {
  47.         int c = rand() % 10;
  48.         cur += c + '0';
  49.         found(cur);
  50.     }
  51.  
  52.     if (cur.length() < res) {
  53.         res = cur.length();
  54.         printf("%s\b", cur.c_str());
  55.     }
  56. }
  57.  
  58. int main() {
  59. #ifndef ONLINE_JUDGE
  60.     freopen("input.txt", "r", stdin);
  61. #endif 
  62.     freopen("output.txt", "w", stdout);
  63.    
  64.  
  65.     while (true) {
  66.         solve();
  67.     }
  68.    
  69.  
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement