-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathmain.cpp
41 lines (37 loc) · 916 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
const int NUM_DIGITS = 10;
using namespace std;
class Solution {
public:
string getHint(string secret, string guess) {
int len = secret.size();
int a = 0, b = 0;
int secret_counter[NUM_DIGITS] = {0}, guess_counter[NUM_DIGITS] = {0};
for (int i = 0; i < len; i++) {
if (secret[i] == guess[i]) {
a++;
} else {
secret_counter[secret[i] - '0']++;
guess_counter[guess[i] - '0']++;
}
}
for (int i = 0; i < NUM_DIGITS; i++) {
b += min(secret_counter[i], guess_counter[i]);
}
return to_string(a) + "A" + to_string(b) + "B";
}
};
int main() {
Solution sol;
cout << sol.getHint("1123", "0111") << endl;
cout << sol.getHint("1", "0") << endl;
return 0;
}