Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include < iostream >
- //100 000 x
- //100 001 v
- //100 010
- //123 060 v
- //123 124 x
- int main()
- {
- //int ticket{ 123123 };
- //int ticket{ 123060 };
- //int ticket{ 120003 };
- int ticket{ 34578934 };
- //int ticket{ 34575374 };
- int sum{};
- while (ticket)
- {
- ticket > 10000 ? sum += ticket % 10 : sum -= ticket % 10;
- ticket /= 10;
- }
- if (!sum)
- {
- std::cout << "Lucky ticket! :)\n";
- }
- else
- {
- std::cout << "UNLUCKY ticket! :(\n";
- }
- return 0;
- int ticketL{ ticket / 1000 };
- int ticketR{ ticket % 1000 };
- std::cout << "ticket = " << ticket << " ticketL = " << ticketL << " ticketR = " << ticketR << '\n';
- int sumL{ 0 };
- int sumR{ 0 };
- //sumL += ticketL % 10; ticketL /= 10;
- //sumL += ticketL % 10; ticketL /= 10;
- //sumL += ticketL % 10; ticketL /= 10;
- while (ticketL)
- {
- sumL += ticketL % 10; ticketL /= 10;
- }
- std::cout << "sumL " << sumL << '\n';
- //sumR += ticketR % 10; ticketR /= 10;
- //sumR += ticketR % 10; ticketR /= 10;
- //sumR += ticketR % 10; ticketR /= 10;
- while (ticketR)
- {
- sumR += ticketR % 10; ticketR /= 10;
- }
- std::cout << "sumR " << sumR << '\n';
- if (sumL == sumR)
- {
- std::cout << "Lucky ticket! :)\n";
- }
- else
- {
- std::cout << "UNLUCKY ticket! :(\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement