×

# python vs Java ??

 0 Somebody please answer Here is a very simple spoj question link http://www.spoj.com/problems/JULKA/ my python code is getting WA where as the same logic Java code is getting AC why what am i missing?? PYTHON3 : (This same code gets AC for python 2.7 with necessary adjustments to code syntax but gives WA for Python 3 Why?) __author__ = "Achut" for i in range(10): a = int(input().strip()) b = int(input().strip()) k = int((a+b)/2) print(k) n = a - k print(n)  Java : import java.util.*; import java.math.*; class JULKA { public static void main(String args[]) { Scanner in = new Scanner(System.in); for (int t = 0; t < 10; t++) { BigInteger A = new BigInteger(in.next()); BigInteger B = new BigInteger(in.next()); BigInteger K = (A.add(B)).divide(new BigInteger("2")); BigInteger N = A.subtract(K); System.out.println(K.toString()); System.out.println(N.toString()); } } }  asked 31 May '14, 01:27 66●2●8 accept rate: 16%

 0 n = a - res Where did the variable res come from????????????????????? That should be k my boy !! :D And next time dont be in a hurry to post doubts on the forum. IT might be a simple mistake but will cost you a lot if you cannot find it on your own during a contest or an interview . Learn to debug on your own! answered 31 May '14, 01:54 3★kcahdog 10.0k●28●54●129 accept rate: 14% sorry thats k i initially used res for python for matching the java code i changed it (31 May '14, 02:05) i used the variables correct in the original code if it were a variable then it wont give WA it would give compilation error (31 May '14, 02:08)
 0 Yeah it should be 'k' inspite of res . answered 31 May '14, 02:05 0★saiiif 1●1 accept rate: 0% yeah thats k i initially used res for python for matching the java code i changed it i used the variables correct if it were a variable then it wont give WA it would give compilation error (31 May '14, 02:08)
 0 @achut i have submitted that problem in python 2.7 just now and i got AC with this code so just check it out. t=10 while t: n=input() n=int(n) k=input() k=int(k) n=n-k n=n/2 print n+k print n t=t-1  answered 31 May '14, 11:43 1.7k●1●17●30 accept rate: 11% If i put print(n+k) and print(n) instead and submit in python 3 i am getting WA even for your solution , why? (31 May '14, 14:48) @achut it is difficult to tell the exact problem.I myself did not submitted it in python 3.0 because someone has already mentioned it in comments that submission in python 3.0 caused him many WAs.so,check out is there any accepted submission in python3.0 or not (31 May '14, 15:37) @ma5termind thanks for you response (31 May '14, 17:34)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,314
×1,138
×529

question asked: 31 May '14, 01:27

question was seen: 1,928 times

last updated: 31 May '14, 17:34