Codeforces Round #306 (Div. 2) 550C - Divisibility by Eight Solution

                                                


  Problem Link: https://codeforces.com/problemset/problem/550/C

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. int main() {
  10. ios_base::sync_with_stdio(0);
  11. cin.tie(0);
  12. string s;
  13. cin >> s;
  14. s = "00" + s;
  15. int n = s.size();
  16. int i, j, k, a, b, c;
  17. bool f = false;
  18. for (int i = 0; i < n; i++) {
  19. for (int j = i + 1; j < n; j++) {
  20. for (int k = j + 1; k < n; k++) {
  21. a = s[i] - '0';
  22. b = s[j] - '0';
  23. c = s[k] - '0';
  24. int num1 = (a * 100) + (b * 10) + c;
  25. if (num1 % 8 == 0) {
  26. cout << "YES" << endl;
  27. cout << num1 << endl;
  28. return 0;
  29. }
  30. }
  31. }
  32. }
  33. cout << "NO" << endl;
  34. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.