artemgf

Числа-перевёртыши

Mar 19th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <math.h>
  4. #include <string>
  5. #include <algorithm>
  6.  
  7. using namespace ::std;
  8.  
  9. int main()
  10. {
  11.     int n, j;
  12.     string data[100];
  13.     bool r = false;
  14.  
  15.     cin >> n;
  16.  
  17.     for (int i = 0; i <= 99; i++)
  18.         data[i] = "80";
  19.  
  20.     for (int i = 1; i <= 99 - n; i++)
  21.     {
  22.         for (j = 0; j < n; j++)
  23.         {
  24.             if ((i + j) % 10 == 1 || (i + j) % 10 == 0 || (i + j) % 10 == 6 || (i + j) % 10 == 8 || (i + j) % 10 == 9)
  25.             {
  26.                 if ((i + j) / 10 == 1 || (i + j) / 10 == 0 || (i + j) / 10 == 6 || (i + j) / 10 == 8 || (i + j) / 10 == 9)
  27.                 {
  28.                     data[j + 1][1] = (i + j) % 10 + '0';
  29.                     data[j + 1][0] = (i + j) / 10 + '0';
  30.                 }
  31.                 else
  32.                     break;
  33.             }
  34.             else
  35.                 break;
  36.         }
  37.         if (j == n)
  38.         {
  39.             r = true;
  40.             break;
  41.         }
  42.     }
  43.  
  44.     if (r == true)
  45.         for (int k = n; k >=1; k--)
  46.         {
  47.             if (data[k][1] == '6')
  48.             {
  49.                 cout << 9;
  50.             }
  51.             else
  52.                 if (data[k][1] == '9')
  53.                     cout << 6;
  54.                 else
  55.                     cout << data[k][1];
  56.             if (data[k][0] == '6')
  57.                 cout << 9 << " ";
  58.             else
  59.                 if (data[k][0] == '9')
  60.                     cout << 6 << " ";
  61.                 else
  62.                     cout << data[k][0] << " ";
  63.         }
  64.     else
  65.         cout << "Glupenky Pierre";
  66.  
  67.     _getch();
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment