Advertisement
avr39ripe

SBULuckyTickets

Jun 6th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include < iostream >
  2.  
  3. //100 000 x
  4. //100 001 v
  5. //100 010
  6. //123 060 v
  7. //123 124 x
  8.  
  9.  
  10. int main()
  11. {
  12.     //int ticket{ 123123 };
  13.     //int ticket{ 123060 };
  14.     //int ticket{ 120003 };
  15.     int ticket{ 34578934 };
  16.     //int ticket{ 34575374 };
  17.     int sum{};
  18.  
  19.     while (ticket)
  20.     {
  21.         ticket > 10000 ? sum += ticket % 10 : sum -= ticket % 10;
  22.         ticket /= 10;
  23.     }
  24.  
  25.     if (!sum)
  26.     {
  27.         std::cout << "Lucky ticket! :)\n";
  28.     }
  29.     else
  30.     {
  31.         std::cout << "UNLUCKY ticket! :(\n";
  32.     }
  33.  
  34.     return 0;
  35.  
  36.     int ticketL{ ticket / 1000 };
  37.     int ticketR{ ticket % 1000 };
  38.  
  39.     std::cout << "ticket = " << ticket << " ticketL = " << ticketL << " ticketR = " << ticketR << '\n';
  40.  
  41.     int sumL{ 0 };
  42.     int sumR{ 0 };
  43.  
  44.     //sumL += ticketL % 10; ticketL /= 10;
  45.     //sumL += ticketL % 10; ticketL /= 10;
  46.     //sumL += ticketL % 10; ticketL /= 10;
  47.  
  48.     while (ticketL)
  49.     {
  50.         sumL += ticketL % 10; ticketL /= 10;
  51.     }
  52.  
  53.     std::cout << "sumL " << sumL << '\n';
  54.  
  55.     //sumR += ticketR % 10; ticketR /= 10;
  56.     //sumR += ticketR % 10; ticketR /= 10;
  57.     //sumR += ticketR % 10; ticketR /= 10;
  58.  
  59.     while (ticketR)
  60.     {
  61.         sumR += ticketR % 10; ticketR /= 10;
  62.     }
  63.  
  64.     std::cout << "sumR " << sumR << '\n';
  65.  
  66.     if (sumL == sumR)
  67.     {
  68.         std::cout << "Lucky ticket! :)\n";
  69.     }
  70.     else
  71.     {
  72.         std::cout << "UNLUCKY ticket! :(\n";
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement