题目大意:求符合要求的密码的个数
思路解析:无脑暴力枚举。5重循环干就完了。(计数可能会有重复,建议使用容器set或map来去重)
废话不多说,代码如下:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using T = pair<int, int>;
//set<int>S;
unordered_map<int, int>mp;
const ll N = 1e9 + 7;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t; cin >> t;
while (t--) {
mp.clear();
int cnt; cin >> cnt;
string s; cin >> s;
ll y; cin >> y;
int i, j, k, l, m;
for (i = 0; i <= 9; ++i) {//a
for (j = 0; j <= 9; ++j) {//b
for (k = 0; k <= 9; ++k) {//c
for (l = 0; l <= 9; ++l) {//d
for (m = 0; m <= 9; ++m) {//_
if (i == j || i == k || i == l || j == k || j == l || k == l)continue;
int n;
ll res{};
for (n = 0; n < s.size(); ++n) {
if (cnt != 1) {
if (s[0] == '0')break;
if (s[0] == 'a' && i == 0)break;
if (s[0] == 'b' && j == 0)break;
if (s[0] == 'c' && k == 0)break;
if (s[0] == 'd' && l == 0)break;
if (s[0] == '_' && m == 0)break;
}
if (s[n] >= '0' && s[n] <= '9')res = res * 10 + (s[n] - '0');
if (s[n] == 'a')res = 10 * res + i;
if (s[n] == 'b')res = 10 * res + j;
if (s[n] == 'c')res = 10 * res + k;
if (s[n] == 'd')res = 10 * res + l;
if (s[n] == '_')res = 10 * res + m;
}
if ((n<s.size()) || (res % 8 != 0) || (res>y))continue;
mp[res] = 1;
}
}
}
}
}
cout << mp.size() << endl;
}
return 0;
}