// This code written by B.Tserenchimed // Source name: "hevleh_mashin.cpp" #include "spoj.h" #include <cstdio> #include <string> #include <map> using namespace std; int main(){ spoj_init(); /* spoj_p_out: correct output spoj_p_in : correct input spoj_t_out: output of the program spoj_score: score board */ int nTest,nAnswer,nWord,index,nCommand; bool used[25001]={0}; char firstLetter,word[40],command[40]; fscanf(spoj_p_out, "%d", &nTest); fscanf(spoj_t_out, "%d", &nAnswer); if (nTest!=nAnswer) //minimum number of commands return 1; map<string, int> dictionary; map<string, int>::iterator lookup; fscanf(spoj_p_in,"%d",&nWord); for (index=0;index<nWord;index++){ fscanf(spoj_p_in,"%s",word); string s_word(word); dictionary[s_word]=index; //indexing each word in its order } index=0; nCommand=0; while(fscanf(spoj_t_out,"%s",command)==1){ nCommand++; firstLetter=command[0]; if ('a'<=firstLetter&&firstLetter<='z'){ word[index++]=firstLetter; if (index>30) return 1; //too long, returning "Wrong Answer" } else if (firstLetter=='-'){ index--; if (index<0) return 1; //can't delete letter } else if (firstLetter=='P'){ word[index]=0; string s_word(word); lookup=dictionary.find(s_word); if (lookup==dictionary.end()) return 1; //no such word in dictionary if (used[lookup->second]) return 1; //already printed word else used[lookup->second]=true; //this word is printed! } } if (nCommand!=nAnswer) return 1; //not same number of command for (index=0;index<nWord;index++) if (used[index]==false) return 1; //found nonprinted word fprintf (spoj_score, "%d\n",1); //spoj_final(); //please comment it return 0; //return "Accepted" }

inserted by FC2 system