a291.
nAnB problem
| From: [49.217.199.236] |
發表日期
:
2024-05-11 13:10
//a229
#include <bits/stdc++.h>
using namespace std;
void compare(string ansr, string keyr){
int a = 0, b = 0;
int ans[4], key[4];
vector<int> used;
for(int i = 0 ; i < 7; i+=2){
ans[i/2] = ansr[i] - '0';
key[i/2] = keyr[i] - '0';
if(ans[i/2] == key[i/2]){
a++;
used.push_back(i/2);
ans[i/2] = 10;
key[i/2] = 10;
}
}
for(int i = 0 ; i < 4; i++){
for(int j = 0 ; j < 4; j++){
if(ans[i] != 10 && key[j] != 10){
if(ans[i] == key[j]){
b++;
ans[i] = 10;
key[j] = 10;
}
}
}
}
cout << a << 'A'<< b << 'B' << endl;
}
void solve(string ans){
string n;
getline(cin, n);
string key;
for(int i = 1; i <= n[0] - '0' ; i++){
getline(cin, key);
compare(ans, key);
}
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
int main(){
string s;
while(getline(cin, s))
solve(s);
}