Petro_zzz

lesson14_321

Sep 6th, 2023
1,135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. using namespace std;
  4.  
  5. void task1() {
  6.     int a = 55;
  7.     int b = 43;
  8.     int c, d;
  9.     c = a++;
  10.     d = ++b;
  11.     cout << c << " " << d << endl;
  12. }
  13.  
  14. void dowhile_task0() {
  15.     int k = 0, n = 0;
  16.     do {
  17.         n = 0;
  18.         do {
  19.             cout << "* ";
  20.             n++;
  21.         } while (n <= k);
  22.         cout << endl;
  23.         k++;
  24.     } while (k < 5);
  25. }
  26.  
  27. void while_task0() {
  28.     int k = 0, n = 0;
  29.     while (k <= 5) {
  30.         n = 0;
  31.         while (n < k) {
  32.             cout << "*";
  33.             n++;
  34.         }
  35.         cout << endl;
  36.         k++;
  37.     }
  38. }
  39.  
  40. void for_task0() {
  41.     for (int k = 0; k <= 5; k++) {
  42.         for (int n = 0; n < k; n++) {
  43.             cout << "*";
  44.         }
  45.         cout << endl;
  46.     }
  47. }
  48.  
  49. void task3() {
  50.  
  51.     for (int n = 1; n <= 500; n++) {
  52.         if (n % 3 == 0)
  53.             continue;
  54.         if (n % 7 == 0)
  55.             continue;
  56.         if (n % 27 == 0)
  57.             continue;
  58.         if (n % 29 == 0)
  59.             continue;
  60.         //cout << n << ((n != 500)? ", " : "");
  61.         cout << n;
  62.         if (n != 500)
  63.             cout << ", ";
  64.     }
  65.     cout << endl;
  66. }
  67.  
  68. void fibbo() {
  69.     int f_old = 1;     // F1
  70.     int f_old_old = 0; // F0
  71.     int f = 0;
  72.     cout << f_old_old << " ";
  73.     cout << f_old << " ";
  74.     for (int n = 0; n <= 20; n++) {
  75.         f = f_old + f_old_old;
  76.         cout << f << " ";
  77.         f_old_old = f_old;
  78.         f_old = f;
  79.     }
  80.     cout << endl;
  81. }
  82.  
  83. void lucky_ticket() {
  84.     int a1, a2, a3, a4, a5, a6;
  85.     int val, num_lucky = 0;
  86.  
  87.     for (int n = 1; n < 1000000; n++) {
  88.         val = n;
  89.  
  90.         a6 = val % 10;
  91.         val = val / 10;
  92.  
  93.         a5 = val % 10;
  94.         val = val / 10;
  95.  
  96.         a4 = val % 10;
  97.         val = val / 10;
  98.  
  99.         a3 = val % 10;
  100.         val = val / 10;
  101.  
  102.         a2 = val % 10;
  103.         val = val / 10;
  104.  
  105.         a1 = val % 10;
  106.  
  107.         if (a1 + a2 + a3 == a4 + a5 + a6) {
  108.             cout << a1 << a2 << a3 << " " << a4 << a5 << a6 << endl;
  109.             num_lucky++;
  110.             continue;
  111.         }
  112.         if ((a1 + a2 == a3 + a4 + a5 + a6) ||
  113.             (a3 + a4 == a1 + a2 + a5 + a6) ||
  114.             (a5 + a6 == a1 + a2 + a3 + a4)) {
  115.             //cout << a1 << a2 << a3 << " " << a4 << a5 << a6 << endl;
  116.             //num_lucky++;
  117.             continue;
  118.         }
  119.         if (((a1 - a2) == 1) && ((a1 - a3) == 2) &&
  120.             ((a1 - a4) == 3) && ((a1 - a5) == 4) &&
  121.             ((a1 - a6) == 5)) {
  122.             //cout << a1 << a2 << a3 << " " << a4 << a5 << a6 << endl;
  123.             //num_lucky++;
  124.             continue;
  125.         }
  126.     }
  127.     cout << endl << num_lucky << endl;
  128. }
  129.  
  130. int main() {
  131.     //task1();
  132.     //task1();
  133.     //fibbo();
  134.     lucky_ticket();
  135.     return 0;
  136.    
  137. }
Advertisement
Add Comment
Please, Sign In to add comment