On Wednesday, March 20, 2019 at 12:58:49 AM UTC+8, Paul Smith wrote:
> But they are still strings, so they will compare like strings.
> 
> Try the test case "1 02 3"
> 
> 
> Numerically this is already in order so should receive "OK", but 
> lexicographically it isn't, so your code outputs 0.
> 
> 
> Your code is fine on "1 2 3"
> 
> 
> So, like Luke already said, you need to convert the things in ls to integers.
> 
> 
> On Tue, 19 Mar 2019 at 14:55 Ho Wei Hong <[email protected]> wrote:
> it's in python
> 
> i threw the whole string into 2 list, ls1 and ls2
> 
> ls1 holds all even indices(0,2,4,...) of string
> 
> ls2 holds all odd indices of string
> 
> sorted them
> 
> I used the "shoelace" method to compare to the indices before that
> 
> 
> 
> 
> 
> On Tuesday, March 19, 2019 at 5:03:42 AM UTC+8, Luke Pebody wrote:
> 
> > I don't actually know what language this is. They all look the same to me 
> > now. But I think the things in your sequence ls are strings and you need to 
> > convert them to integers.
> 
> > 
> 
> > 
> 
> > On Mon, 18 Mar 2019, 8:00 pm Ho Wei Hong <[email protected] wrote:
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > Hi all,
> 
> > 
> 
> > 
> 
> > 
> 
> > I am having some problems with my code. I think I have the answer but 
> > somehow the grader mark me wrongly. I can't think of any cases that I might 
> > have miss out. I be glad if somebody can enlighten me. I placed the link of 
> > problem here for easy access
> 
> > 
> 
> > 
> 
> > 
> 
> > https://codingcompetitions.withgoogle.com/codejam/round/00000000000000cb/00000000000079cb
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > def main():
> 
> > 
> 
> >     for i in range(int(input())):
> 
> > 
> 
> >         n = int(input())
> 
> > 
> 
> >         ls = input().split(" ")
> 
> > 
> 
> >         c = sol(ls,n)
> 
> > 
> 
> >         print("Case #{}: {}".format(i+1, c))
> 
> > 
> 
> > 
> 
> > 
> 
> > def sol(ls,n):
> 
> > 
> 
> >     ls1=[]
> 
> > 
> 
> >     ls2=[]
> 
> > 
> 
> >     i=0
> 
> > 
> 
> >     while i<n:
> 
> > 
> 
> >         if i%2==0:
> 
> > 
> 
> >             ls1.append(ls[i])
> 
> > 
> 
> >         else:
> 
> > 
> 
> >             ls2.append(ls[i])
> 
> > 
> 
> >         i+=1
> 
> > 
> 
> >     ls1.sort()
> 
> > 
> 
> >     ls2.sort()
> 
> > 
> 
> >     #print(ls1,'\n',ls2)
> 
> > 
> 
> >     b=0
> 
> > 
> 
> >     e1,e2=0,0
> 
> > 
> 
> >     for i in range(n//2):
> 
> > 
> 
> >         if ls1[i]>ls2[i]:
> 
> > 
> 
> >             #print(ls1[i],ls2[i])
> 
> > 
> 
> >             e1 = 2*i
> 
> > 
> 
> >             b+=1
> 
> > 
> 
> >             break
> 
> > 
> 
> >     for i in range((n-1)//2):
> 
> > 
> 
> >         if ls2[i]>ls1[i+1]:
> 
> > 
> 
> >             e2 = 2*(i+1)-1
> 
> > 
> 
> >             b+=1
> 
> > 
> 
> >             break
> 
> > 
> 
> >     if b==2:
> 
> > 
> 
> >         return min(e1,e2)
> 
> > 
> 
> >     elif b==1: return max(e1,e2)
> 
> > 
> 
> >     else: return 'OK'
> 
> > 
> 
> > 
> 
> > 
> 
> > main()
> 
> > 
> 
> > 
> 
> > 
> 
> > -- 
> 
> > 
> 
> > You received this message because you are subscribed to the Google Groups 
> > "Google Code Jam" group.
> 
> > 
> 
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to [email protected].
> 
> > 
> 
> > To post to this group, send email to [email protected].
> 
> > 
> 
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/google-code/720d21f7-06c6-44d9-b676-eaf76231a502%40googlegroups.com.
> 
> > 
> 
> > For more options, visit https://groups.google.com/d/optout.
> 
> 
> 
> -- 
> 
> You received this message because you are subscribed to the Google Groups 
> "Google Code Jam" group.
> 
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> 
> To post to this group, send email to [email protected].
> 
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/google-code/0069c127-fe2c-4734-afd9-a0453ca23674%40googlegroups.com.
> 
> For more options, visit https://groups.google.com/d/optout.

OMG, thank you. you are completely right. just changing the line to

ls = [int(x) for x in input().split(" ")]

i got the right answer. thank you Paul and Luke. i will keep going in 
practicing more problems!

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/592872d9-3bd5-43c6-8868-646849a32863%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to