Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Get Pattern of Even & Odd Numbered Months of Year in Python Programming

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 626
    Answer it

    I don't know why I get a wrong answer for this question. Help please.

     

    Chef has decided to start a new firm called PatentChef. However, he's stuck with some big legal issues. Their firm has received offers from a lot of companies, so Chef told his friend Junior Chef to look over some patent cases and solve them as quickly as he can.

     

    Junior Chef is very smart and has an eye for every little detail. He quickly found a case and went ahead to solve it. The patent case is as follows:

     

    There are N patents to be filed for a company. Chef’s firm has the first M months of the year 2018 to finish this task. (The months in a year are numbered 1 through 12.) Chef's firm has K workers (including Junior Chef) available to work on this case. Each worker can prepare exactly one patent per month.

     

    Junior Chef assigns work to workers starting from the first month of the year. He can have any workers work on this case on any month provided that they're chosen according to the following conditions:

     

    Each worker can only work on this patent case for at most one month.


    Each worker has to work either on an even month or an odd month of the year. You are given a string S with length K and the following meaning: for each valid i, if the i-th character of S is E, worker i has to work on an even month; if it's O, this worker has to work on an odd month.


    At most X workers can work on this patent case each month.

     

    Determine whether Chef’s firm and Junior Chef can finish this patent case in time. Input

     

    • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
    • The first line of each test case contains four space-separated integers N, M, X and K.
    • The second line contains a single string S.

     

    For each test case, print a single line containing the string "yes" if it's possible to finish the patent case or "no" otherwise (without quotes).
    Example

     

    Input:

    2
    4 4 2 4
    EEOO
    4 3 1 4
    EEOO

    Output:

    yes
    no

    My solution, in python, which was declared wong.

    for t in xrange(int(raw_input())):
        n, m, x, k = map(int, raw_input().split())
        s = raw_input()
        even = m/2
        odd = m - even
        e, o = 0, 0
        work, worked = 0, 0
        for i in s:
            if i == 'E':
                e += 1
            else:
                o += 1
        for k in xrange(even):
            if e > 0 and e >= x:
                worked += x
                e -= x
            elif e > 0 and e < x:
                worked += e
                e -= e
        for j in xrange(odd):
            if o > 0 and o >= x:
                work += x
                o -= x
            elif o > 0 and o < x:
                work += o
                o -= o
        if work + worked == n:
            print 'yes' #+ str(work+worked)
        else:
            print 'no' #+ str(work+worked)

     

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: