제출 #1317689

#제출 시각아이디문제언어결과실행 시간메모리
1317689matrix081Memory (IOI10_memory)C++20
컴파일 에러
0 ms0 KiB
#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)] = -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; int candies = 0; while(candies < 25 && first_card < 50) { while(first_card < 50 && matched(faceup(first_card))) first_card++; if(first_card >= 50) break; char a = faceup(first_card); if(!seen(a)) mark_seen(a, first_card); int second_card; if(seen(a) && !matched(a) && !same(a, first_card)){ second_card = get_pos(a); } else { second_card = first_card + 1; while(second_card < 50 && matched(faceup(second_card))) second_card++; if(second_card >= 50) second_card = first_card; } char b = faceup(second_card); if(!seen(b)) mark_seen(b, second_card); if(a == b){ candies++; mark_match(a); mark_match(b); } first_card++; } }

컴파일 시 표준 에러 (stderr) 메시지

memory.cpp: In function 'void play()':
memory.cpp:106:5: error: redeclaration of 'int candies'
  106 | int candies = 0;
      |     ^~~~~~~
memory.cpp:50:27: note: 'int candies' previously declared here
   50 |    int i,j, to_use_for_b, candies=0;
      |                           ^~~~~~~