1 / 3
Sep 2009

Hi Admin,

I've been trying to make a successful submission for "1163. Java vs C ++" ( spoj.pl/problems/JAVAC/), but to all my attempts i get an
"runtime error (NZEC)". having already spent hours drooling over the code, I can't find the reason why my code is failing.

my submission ID is 2766856, admin can you please tell me the error code against my submission.

also, please comment on code snippet responsible for reading input:

def main():
	while True:
		try:
			string = raw_input()
		except:
			break
		if string.find('_') != -1:
			toJavaMnemonic(string)
		else:
			toCPPMnemonic(string)

Thanks.

  • created

    Sep '09
  • last reply

    Mar '10
  • 2

    replies

  • 138

    views

  • 3

    users

  • 1

    link

5 months later

me too getting a NZEC for this problem.
Could anyone please point out the error. I'm new to python

def has_underscore(identifier):
    if identifier.find('_') == -1: return False
    else: return True
def has_uppercase(identifier):
    for ch in identifier:
        if ch.isupper(): return True
    return False
def to_java(identifier):
    st = []
    i, Z = 0, len(identifier)
    while i < Z:
        if identifier[i] == '_':
            i += 1
            st.append(identifier[i].upper())
        else:
            st.append(identifier[i])
        i += 1
    return ''.join(st)
def to_cpp(identifier):
    st = []
    i, Z = 0, len(identifier)
    while i < Z:
        if identifier[i].isupper():
            st.extend(['_', identifier[i].lower()])
        else:
            st.append(identifier[i])
        i += 1
    return ''.join(st)
def main():
    while True:
        try:
            st = input()
        except EOFError:
            return 0
        st = st.rstrip()
        cpp_flag = has_underscore(st)
        java_flag = has_uppercase(st)
        if cpp_flag and java_flag:
            print('Error!')
            continue
        elif cpp_flag:
            print(to_java(st))
        else:
            print(to_cpp(st))        
if __name__ == '__main__':
    main()

Test your code with the sample testcases on your local machine with python 2.5 oder python 2.6 and you'll find out yourself what is wrong. I guess you used python 3.x for testing ...

Suggested Topics

Want to read more? Browse other topics in Python or view latest topics.