import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String[] lines1;
int count = 0;
while(true){//시나리오 관리
lines1 = br.readLine().split(" ");
String[] lines2;
if(lines1[0].equals("0") && lines1[1].equals("0")){
break;
}
int goalState = Integer.parseInt(lines1[0]);
int state = Integer.parseInt(lines1[1]);
boolean deadCheck = false;
count++;
while(true){//시나리오 실행
lines2 = br.readLine().split(" ");
if(lines2[0].equals("#") && lines2[1].equals("0"))
break;
String action = lines2[0];
int value = Integer.parseInt(lines2[1]);
if(action.equals("F")){
state += value;
}else if(action.equals("E")){
state -= value;
if(state <=0)
deadCheck = true;
}
}
if(!deadCheck && (state > goalState/2 && state < 2*goalState)){//펫 상태 체크
bw.write(String.format("%d :-)",count));
}else if(deadCheck)
{
bw.write(String.format("%d RIP",count));
}
else{
bw.write(String.format("%d :-(",count));
}
bw.newLine();
}
bw.flush();
bw.close();
}
}
댓글 영역