#include "grader.h"
#include "memory.h"
#include <vector>
#include <iostream>
using namespace std;
vector <int> guessed(25, -1);
void mark_match(char b){
guessed[int(b)-65] = -2;
}
void mark_seen(char b, int index){
guessed[int(b)-65] = index;
}
bool matched(char b){
if(guessed[int(b)-65]==-2){
return true;
}
else{
return false;
}
}
bool seen(char b){
if(guessed[int(b)-65]!=-1){
return true;
}
else{
return false;
}
}
bool same(char a, int index){
if(guessed[int(a)-65]==index){
return true;
}
else{
return false;
}
}
int get_pos(char card_seen){
return guessed[int(card_seen)-65];
}
void play() {
int i,j, to_use_for_b, candies=0;
char a, b,c,d;
// when we meet a letter we have not seen before store it in the guessed array
// if we have seen it before a dn we are at a, call b on the index in the array
// if we are at b and have seen it before continue
// for (i=0; i<50&&candies<25; i++) {
// a = faceup(i);
// if(guessed[int(a)-65]==-1){ // have not seen it before
// guessed[int(a)-65] = i;
// to_use_for_b = i+1;
// b = faceup(to_use_for_b);
// if(guessed[int(b)-65]==-1 &&i<49){
// guessed[int(b)-65] = i+1; // if I havent met b before I save it;
// }
// }
// else{ // my case where we have met it before ;
// if(guessed[int(a)-65]!=-2 && guessed[int(a)-65]!=-1 && guessed[int(a)-65]!=i){
// to_use_for_b = guessed[int(a)-65];
// b = faceup(to_use_for_b);
// if(a==b){
// guessed[int(a)-65] = -2;
// candies+=1;
// i+=1;
// }
// }
// else{
// to_use_for_b = i+1;
// b = faceup(to_use_for_b);
// }
// }
// }
// }
// for (i=0; i<50 && candies<=25; i++){
// c = faceup(i);
// if(int(c)-65 == i){
// faceup(i+1);
// continue;
// }
// d = faceup(guessed[int(c)-65]);
// if(c==d){
// candies+=1;
// }
// }
int first_card = 0;
int second_card;
while(candies < 25 && first_card < 50){
if(first_card >= 50) break;
char a = faceup(first_card);
if(!seen(a)) mark_seen(a, first_card);
if(seen(a) && !matched(a) && !same(a, first_card)){
second_card = get_pos(a);
} else {
second_card = first_card + 1;
}
char b = faceup(second_card);
if(!seen(b)) mark_seen(b, second_card);
if(a == b){
mark_match(a);
mark_match(b);
candies++;
}
first_card++;
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |