Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int n;
- int main()
- {
- int n;
- cin >> n;
- string s;
- cin >> s;
- int combs = 0;
- for(int mask = 0; mask < (1 << n); mask++) {
- string tmp = "";
- for(int i = 0; i < n; i++) {
- if(mask & (1 << i)) {
- tmp += s[i];
- }
- }
- string ltd = "";
- if(tmp.size() == 1) {
- ltd += tmp[tmp.size() - 1];
- }
- else if(tmp.size() == 2) {
- ltd += tmp[tmp.size() - 2];
- ltd += tmp[tmp.size() - 1];
- }
- else {
- ltd += tmp[tmp.size() - 3];
- ltd += tmp[tmp.size() - 2];
- ltd += tmp[tmp.size() - 1];
- }
- int num = 0;
- for(int j = 0; j < ltd.size(); j++) {
- num = (num * 10) + (ltd[j] - '0');
- }
- if(num % 8 == 0) {
- ++combs;
- }
- }
- cout << combs - 1<< endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement