1 / 6
Mar 2023
# Need a little help on this one I cannot find why I am getting WA
# https://www.spoj.com/problems/DIGSHIFT/
tests=int(input())
for test in range(1, tests+1):
    print("Case " + str(test) + ":")
    x = input()
    y = [[x[0], 1]]
    for i in range(1, len(x)):
        if y[-1][0] == x[i]:
            y[-1][1] += 1
        else:
            y.append([x[i], 1])
    q = int(input())
    for query in range(q):
        d = input()
        cnt = 0
        l = len(y)
        for i in range(0, l):
            if d[0] == y[l-1-i][0]:
                cnt += y[l-1-i][1]
                del y[l-1-i]
        y.append([d, cnt])
        res = ''
        for a in y:
            res += a[0]*a[1]
        print(int(res)%1000000007)
  • created

    Mar '23
  • last reply

    Mar '23
  • 5

    replies

  • 506

    views

  • 2

    users

  • 1

    like

Try this test case:

1
1234034776123642347472389473895613497284734723471489571713440100
1
8

Hello, Thanks for the reply.
The result should be:
1234034776123642347472394739561349724734723471495717134401008888%1000000007 ===> 508679078
I get 508679078
It looks correct to me.

OK, I’ll try again… try this:

1
220011
7
6
0
1
0
2
1
0

My (unaccepted!) code gives

Case 1:
220011
221100
220011
221100
110022
2211
2211

Your code gives

Case 1:
220011
221100
220011
221100
110022
2211
221100

I think those zeros in the final answer should have been discarded.

You are right I did not read the problem properly. Thanks.