I keep getting a runtime error in the Moons and Umbrellas problem in the google code jam
Here is my code:
indent preformatted text by 4 spaces
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
I have never asked like this anytime but this question is just giving headache. I have spent half a day on this but not able to figure out what is wrong. I don’t want to ask but I am also at the same time depressed about this question.
Please help me a little bit with a hint or something with reversort engineering question. I have almost all cases on my system and it is working fine but then also getting WA verdict. What can be wrong here?
Well I put that there because we know at that point that the character is “?” and if the character after it isn’t a “?”, I wanted to change it to the “J” or “C” that was in front of it.
T = int(input())
if(T>=1 and T<=100):
pass
else:
raise(“Test Case Out of Bound”)
RES = []
for i in range(T):
temp = list(input().split())
X = int(temp[0])
Y = int(temp[1])
S = list(temp[2])
if(X>=1 and X<=100):
pass
else:
raise(“X value Out of Bound”)
if(Y>=1 and Y<=100):
pass
else:
raise(“Y Value Out of Bound”)
if(len(S)>=1 and len(S)<=1000):
for j in S:
if(j==‘C’ or j==‘J’ or j==’?’):
pass
else:
raise(“S contains invalid characters”)
else:
raise(“S Value Out of Bound”)
if(X>0 and Y>0):
if(S[0] == ‘?’):
prev = 0
else:
prev = 1
for j in range(len(S)):
if(S[j]=='?'):
if(prev == 0 and S[j+1] == 'C'):
for k in range(j+1):
S[k]='C'
prev = 1
elif(prev == 0 and S[j+1] == 'J'):
for k in range(j+1):
S[k]='J'
prev = 1
elif(prev == 1):
S[j]=S[j-1]
S = ''.join([str(elem) for elem in S])
CJ = S.count('CJ')
JC = S.count('JC')
ans = (CJ * X) + (JC * Y)
RES.append(ans)
for i in range(len(RES)):
print(“Case #{}: {}”.format(i+1,RES[i]))
T = int(input())
if(T>=1 and T<=100):
pass
else:
raise("Test Case Out of Bound")
RES = []
for i in range(T):
temp = list(input().split())
X = int(temp[0])
Y = int(temp[1])
S = list(temp[2])
if(X>=1 and X<=100):
pass
else:
raise("X value Out of Bound")
if(Y>=1 and Y<=100):
pass
else:
raise("Y Value Out of Bound")
if(len(S)>=1 and len(S)<=1000):
for j in S:
if(j=='C' or j=='J' or j=='?'):
pass
else:
raise("S contains invalid characters")
else:
raise("S Value Out of Bound")
if(X>0 and Y>0):
if(S[0] == '?'):
prev = 0
else:
prev = 1
for j in range(len(S)):
if(S[j]=='?'):
if(prev == 0 and S[j+1] == 'C'):
for k in range(j+1):
S[k]='C'
prev = 1
elif(prev == 0 and S[j+1] == 'J'):
for k in range(j+1):
S[k]='J'
prev = 1
elif(prev == 1):
S[j]=S[j-1]
S = ''.join([str(elem) for elem in S])
CJ = S.count('CJ')
JC = S.count('JC')
ans = (CJ * X) + (JC * Y)
RES.append(ans)
for i in range(len(RES)):
print("Case #{}: {}".format(i+1,RES[i]))