简体   繁体   中英

One test case failed for the python solution. How to correct it.?

I was solving a problem in IndiaHacks in python but one of the test case failed. But when i solved using the same logic in C++ , all the test cases passed.

I figured out that's because of python not being able to get full string as input if the string length is long.

Here is the problem

This is my solution in python

a=input()
s = set(a)

dic = {}

for v in s:
    dic[v] = a.count(v)

if((len(a))%2 == 0):
   ne = set(dic.values())
   if len(ne) == 1:
       print("YES")
   else:
       print("NO")
else:

    co = 0
    for ky in dic:
        if dic[ky]%2 != 0:
            co = co +1
    if co==1:
        print("YES")
    else:
        print("NO")

Here is the input test case which failed

PS: My algorithm is correct . Its just that variable a is not able to get the full string as input.How to get that ? Is there long string in python..?

Have you tried this -

x = sys.stdin.read()

Please note that you have to import sys for using this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM