egogoboy

лексикографический порядок

May 28th, 2022 (edited)
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. int main() {
  5.  
  6.     std::ifstream fin("input.txt");
  7.     std::ofstream fout("output.txt");
  8.  
  9.     int n, k;
  10.  
  11.     fin >> n >> k;
  12.  
  13.     int num = 0;
  14.  
  15.     for (int i = 1; i < 10; i++) {
  16.         num++;
  17.         if (i == k) {
  18.             fout << num;
  19.             return 0;
  20.         }
  21.         std::cout << i << ' ';
  22.         for (int j = i * 10; j < i * 10 + 10 && j <= n; j++) {
  23.             num++;
  24.             std::cout << j << ' ';
  25.             if (j == k) {
  26.                 fout << num;
  27.                 return 0;
  28.             }
  29.             for (int q = j * 10; q < j * 10 + 10 && q <= n; q++) {
  30.                 num++;
  31.                 std::cout << q << ' ';
  32.                 if (q == k) {
  33.                     fout << num;
  34.                     return 0;
  35.                 }
  36.                 for (int d = q * 10; d < q * 10 + 10 && d <= n; d++) {
  37.                     num++;
  38.                     std::cout << d << ' ';
  39.                     if (d == k) {
  40.                         fout << num;
  41.                         return 0;
  42.                     }
  43.                     for (int t = d * 10; t < d * 10 + 10 && t <= n; t++) {
  44.                         num++;
  45.                         std::cout << d << ' ';
  46.                         if (t == k) {
  47.                             fout << num;
  48.                             return 0;
  49.                         }
  50.                     }
  51.                 }
  52.             }
  53.         }
  54.        
  55.     }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment