5 / 5
May 2017

output of my code for duronto eagle is same as expected output. but it is giving time error (NZEC)

n=int(raw_input())
b=list()
i=0
while i<n:
    p=raw_input().split()
    if p!=[]:
        m=int(p[0])
        a=list()
        j=0
        while j<m:
            q=raw_input().split()
            if q!=[]:
                a.append(q)
                j+=1
        d=0
        t=0
        for j in range(m):
            c=(int(a[j][0])**2+int(a[j][1])**2)**0.5
            if d<c:
                d=c
                t=j
        b.append("Case " +str(i+1)+": "+str(t+1))
        b.append("")
        i+=1

for i in range(len(b)-1):
    print b[i]

thanks in advance

  • created

    Feb '16
  • last reply

    May '17
  • 4

    replies

  • 1.4k

    views

  • 3

    users

  • 1

    link

This is an annoying behavior of some SPOJ problems: The input is malformed, e.g. there are tabs or even linebreaks where you expect spaces. Unfortunately Python's input routines are somewhat more sensitive than other languages'. I got an AC using the following input routine:

import sys

def read_all():
    res = []
    for line in sys.stdin.readlines():
        if line.strip():
            parts = line.strip().split()
            res.extend(parts)
    return res
    
numbers = [int(n) for n in read_all()]

And: In Python it is not necessary to use this: for i in range(len(b)-1):
You would always use for entry in b[:-1]
And you would avoid to concetenate strings with "+". Use %s-formatting or .format()

1 year later

Getting the wrong answer problem with my c++ code.Can anyone help please here is the code
<a class="attachment"

include

include

using namespace std;

int main ()
{
int t,i,n,j,x,y,mind=0,cas,dist;
scanf(" %d",&t);
for(i=0;i<t;i++)
{
scanf(" %d",&n);
for(j=0;j<n;j++)
{
scanf(" %d %d",&x,&y);
dist=sqrt((x*x)+(y*y));
if(dist>mind)
{
mind=dist;
cas=j+1;
}
}
printf("Case");
printf(" %d",i+1);
printf(": %d\n",cas);
}
return 0;
}