-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculate.cpp
More file actions
38 lines (36 loc) · 1.02 KB
/
Copy pathcalculate.cpp
File metadata and controls
38 lines (36 loc) · 1.02 KB
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
#include "calculate.hpp"
#include <string>
#include <iostream>
using namespace std;
const bullpgia::Latest_Guess bullpgia::calculateBullAndPgia(string choose, string guess)
{
int Bulls = 0;
int Pgia = 0;
string Choice = "";
string Guess = "";
for (int i = 0; i < choose.length(); i++){
if (choose[i] == guess[i])
Bulls++;
else{
Choice+=choose[i];
Guess += guess[i];
}
}
for (int i = 0; i < Guess.length(); i++){
int place = Choice.find(Guess[i]);
if (place != -1){
Pgia++;
Choice.erase(Choice.begin()+place);
}
}
bullpgia::Latest_Guess a;
a._Bulls=Bulls;
a._Pgia=Pgia;
return a;
}
bool bullpgia::Latest_Guess::operator==(const bullpgia::Latest_Guess res){
return (_Bulls==res._Bulls && _Pgia==res._Pgia);
}
std::ostream& bullpgia::operator <<(std::ostream& out, const bullpgia::Latest_Guess& res){
return out << std::to_string(res._Bulls) << "," + std::to_string(res._Pgia);
}