Advertisement
shek_shek

algebra_5

Mar 20th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stack>
  3. #include <math.h>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <string.h>
  7. #include <string>
  8. #include <set>
  9. #include <memory.h>
  10. #include <vector>
  11. #include <map>
  12. #include <queue>
  13. #include <iomanip>
  14. #include <ctime>
  15. #include <cassert>
  16.  
  17.  
  18.  
  19. #define forn(i, n) for (int i = 0; i < int(n); i++)
  20. #define ll long long
  21. #define mp(a, b) make_pair(a, b)
  22. #define sqr(x) ( (x) * (x) )
  23. #define all(a) a.begin(), a.end()
  24.  
  25. using namespace std;
  26.  
  27. int cnt = 0;
  28.  
  29. void rec(string s, int sz, int pos, int n) {
  30.     if (pos >= sz)
  31.         return;
  32.     for (int i = 0; i < 10; i++) {
  33.         s[pos] = s[s.size() - pos - 1] = '0' + i;
  34.         if (s[0] != '0' && pos == sz - 1)
  35.             cnt++;
  36.         if (cnt == n) {
  37.             cout << s << endl;
  38.             exit(0);
  39.         }
  40.         rec(s, sz, pos + 1, n);
  41.     }
  42. }
  43.  
  44.  
  45. int main() {
  46. #ifdef _DEBUG
  47.     freopen("input.txt", "r", stdin);
  48.     freopen("output.txt", "w", stdout);
  49. #endif
  50.     int t = 1, len = 1;
  51.     int n;
  52.     cin >> n;
  53.     while (1) {
  54.         int sz = (int)(len / 2.0 + 0.5);
  55.         string s = "";
  56.         forn (i, len)
  57.             s += '0';
  58.         rec(s, sz, 0, n);
  59.         len++;
  60.     }
  61.  
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement