Advertisement
Arfizato

fatma

Apr 25th, 2022
1,162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.47 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <inttypes.h>
  3. #include <stdlib.h>
  4. static int64_t the_rolling_stones[] = { 39536, 36819, 31155, 89634, 79345, 63941 };
  5.  
  6. const static int N = sizeof(the_rolling_stones)/sizeof(*the_rolling_stones);
  7.  
  8. static void fail()
  9. {
  10.     puts("Nope!");
  11.     exit(EXIT_FAILURE);
  12. }
  13. static void led_zeppelin(int64_t c, int64_t l, int64_t k)
  14. {
  15.     if ( c - k / 7 + 3 * l / 11 ) //c- (1624/7) + ((3*1441)/11) =0 ==>>> -c= - (1624/7) + ((3*1441)/11)
  16.         fail();
  17. }
  18. static void guns_n_roses(int i, int64_t w)
  19. {
  20.     if (i<N)
  21.     {
  22.         if ((i % 2) == 0)
  23.             guns_n_roses(++i, w);
  24.         else{
  25.             guns_n_roses(i + 1, w + the_rolling_stones[i]);
  26.  
  27.         }
  28.     }
  29.     else if (w != 158946)//c =31052+36819+
  30.         fail();
  31.  
  32. }
  33. static void the_beatles(int b, int64_t h)
  34. {
  35.     int64_t a = h;
  36.     for(; b<N; ++b)
  37.     {
  38.         if (b % 2)
  39.             continue;
  40.         a *= the_rolling_stones[b];
  41.     }
  42.     if (a != 404765760) // 404765760= (8*31155*tab[4]=k) =>>> k= 404765760 / (8*31155)
  43.         fail();
  44. }
  45. int main()
  46. {
  47.     int64_t c, l, k;
  48.     printf("Please enter the right three numbers: ");
  49.     fflush(stdout);
  50.     if (scanf("%" SCNd64 " %" SCNd64 " %" SCNd64, &c, &l, &k) != 3)
  51.         fail();
  52.     the_rolling_stones[0] = c; // -161
  53.     the_rolling_stones[5] = l;//1441
  54.     the_rolling_stones[4] = k;//1624
  55.     guns_n_roses(0, 31052);
  56.     the_beatles(1, 8);
  57.     led_zeppelin(c, l, k);
  58.     puts("Exactly! Good job.");
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement