-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculate.cpp
More file actions
27 lines (24 loc) · 772 Bytes
/
Copy pathcalculate.cpp
File metadata and controls
27 lines (24 loc) · 772 Bytes
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
#include <iostream>
#include "calculate.hpp"
using namespace std;
string calculateBullAndPgia(string choice, string guess){
int bull = 0;
int pgia = 0;
int length = choice.length();
int choiceArray[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int guessArray[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
for(int i=0; i<length; i++){
if(choice.at(i) == guess.at(i)){ bull++;}
else{
int choiceIndex = (int)(choice.at(i) - '0');
int guessIndex = (int)(guess.at(i) - '0');
choiceArray[choiceIndex]++;
guessArray[guessIndex]++;
}
}
for(int i=0; i<10; i++){
pgia += min(choiceArray[i], guessArray[i]);
}
string ans = to_string(bull) + "," + to_string(pgia);
return ans;
}