Advertisement
Hippskill

Untitled

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