Advertisement
Josif_tepe

Untitled

Mar 2nd, 2022
1,274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. int n;
  5.  
  6.  
  7. int main()
  8. {
  9.     int n;
  10.     cin >> n;
  11.     string s;
  12.     cin >> s;
  13.     int combs = 0;
  14.     for(int mask = 0; mask < (1 << n); mask++) {
  15.         string tmp = "";
  16.         for(int i = 0; i < n; i++) {
  17.             if(mask & (1 << i)) {
  18.                 tmp += s[i];
  19.             }
  20.         }
  21.         string ltd = "";
  22.         if(tmp.size() == 1) {
  23.             ltd += tmp[tmp.size() - 1];
  24.         }
  25.         else if(tmp.size() == 2) {
  26.             ltd += tmp[tmp.size() - 2];
  27.             ltd += tmp[tmp.size() - 1];
  28.         }
  29.         else {
  30.             ltd += tmp[tmp.size() - 3];
  31.             ltd += tmp[tmp.size() - 2];
  32.             ltd += tmp[tmp.size() - 1];
  33.         }
  34.         int num = 0;
  35.         for(int j = 0; j < ltd.size(); j++) {
  36.             num = (num * 10) + (ltd[j] - '0');
  37.         }
  38.         if(num % 8 == 0) {
  39.             ++combs;
  40.         }
  41.     }
  42.     cout << combs - 1<< endl;
  43.     return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement