void day2() {
string input1, input2, input3, input4, input5;
int newindex = 0;
int IDsumcopy = 0;
int spacecheck = 0;
bool possible = true;
getline(cin, input1);
getline(cin, input2);
getline(cin, input3);
getline(cin, input4);
getline(cin, input5);
int red = 12;
int green = 13;
int blue = 14;
int IDsum = 0;
int IDsum2 = 0;
vector <int> gameIDS = {};
vector <string> games = { input1, input2, input3, input4, input5 };
for (int game = 0; game < games.size(); game++) { // loop za 4 igre
red = 12;
green = 13;
blue = 14;
possible = true;
vector <char> currentgame = {};
for (int i = 0; i < games[game].size(); i++) { // loopuje za duzinu
svake igre
currentgame.push_back(games[game][i]);
}
for (int i = 4; currentgame[i]!= 'r'; i++) { // sabiranje ID-
ova
if (currentgame[i] == ':') {
for (int b = 0; currentgame[i - b] != 'e'; b++) {
if (isdigit(currentgame[i - b-1])) {
IDsum += (currentgame[i - b-1] - '0') * pow(10, b);
}
}
gameIDS.push_back(IDsum - IDsumcopy);
}
IDsumcopy = IDsum;
newindex = i;
}
for (newindex; newindex < currentgame.size(); newindex++) { //loop za
trenutnu igru
if (possible == false) {
cout << "Game" << gameIDS[game] << " Is impossible" << endl;
break;
}
if (currentgame[newindex - 1] == ' ' && (currentgame[newindex] == 'r'
|| currentgame[newindex] == 'g' || currentgame[newindex] == 'b')) {
for (int b = 0; spacecheck < 2; b++) {
if (currentgame[newindex - b] == ' ') {
spacecheck++;
}
if (isdigit(currentgame[newindex - b - 1])) {
if(currentgame[newindex] == 'r')
red -= (currentgame[newindex - b - 1] - '0') * pow(10,
b-1);
else if(currentgame[newindex] == 'g')
green -= (currentgame[newindex - b - 1] - '0') *
pow(10, b-1);
else if (currentgame[newindex] == 'b')
blue -= (currentgame[newindex - b - 1] - '0') * pow(10,
b-1);
spacecheck = 0;
}
if (currentgame[newindex] == ';') {
red = 12;
green = 13;
blue = 14;
}
if (red < 0 || blue < 0 || green < 0) {
possible = false;
}
}
if (possible == true){
IDsum2 += gameIDS[game];
}
}
cout << IDsum2;