Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. Язык  PCMS Web Client
  2. ИнформацияРезультатыОтправитьРешенияВопросыФайлыСоревнованияВыход
  3. Исходный код
  4. PCMS.cpp
  5. ��#define _CRT_SECURE_NO_WARNINGS
  6. #define FNAME "telemetry"
  7. #include <iostream>
  8. #include <fstream>
  9. #include <algorithm>
  10. #include <string>
  11. #include <vector>
  12. #include <map>
  13. #include <stack>
  14. #include <queue>
  15.  
  16. using namespace std;
  17.  
  18. const int N = 1e5 + 5;
  19.  
  20. vector<int> inc(N, 1);
  21. string a, b;
  22.  
  23. long long n, m, k, x, y, z, ans = 0;
  24.  
  25. void next(int i = 0) {
  26.     if (a[i] + inc[i] >= k + '0' || a[i] + inc[i] < '0') {
  27.         next(i + 1);
  28.         inc[i] *= -1;
  29.     }
  30.     else {
  31.         a[i] += inc[i];
  32.     }
  33. }
  34.  
  35. int main() {
  36. #ifdef _DEBUG
  37.     freopen("input.txt", "r", stdin);
  38.     freopen("output.txt", "w", stdout);
  39. #else
  40.     freopen(FNAME".in", "r", stdin);
  41.     freopen(FNAME".out", "w", stdout);
  42. #endif
  43.     ios::sync_with_stdio(false);
  44.  
  45.     cin >> n >> k;
  46.     a.assign(n, '0');
  47.     b.assign(n, '0' + k - 1);
  48.      
  49.     while (a != b) {
  50.         cout << a << '\n';
  51.         next();
  52.     }
  53.  
  54.     if (k % 2 == 0) {
  55.         b.assign(n - 1, '0');
  56.         b.push_back('0' + k - 1);
  57.         while (a != b) {
  58.             cout << a << '\n';
  59.             next();
  60.         }
  61.     }
  62.  
  63.     cout << a << '\n';
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement