Submission #2417241


Source Code Expand

def solve( s , c ):
    cnt = int(0)
    while 1 :

        if len(s) == 0 :
            return cnt

        f = True

        for i in range(len(s)):
            if s[i] != c:
                f = False
                break
        
        if f :
            return cnt


        s2 = ""
        for i in range(len(s)-1):
            if s[i] == c or s[i+1] == c:
                s2 += c
            else:
                s2 += s[i]
         
        s = s2
        cnt += 1

    return cnt;



s = input()
a = [0 for i in range(26)]

for i in range(len(s)):
    a[ord(s[i])-ord('a')] += 1

ans = 0x7FFFFFFF
for i in range(26):
    if(a[i] > 0 ):
        ans = min( ans , solve(s, chr( i + ord('a') ) ) )

print(ans)

Submission Info

Submission Time
Task A - Shrinking
User walk_to_work
Language C++14 (GCC 5.4.1)
Score 0
Code Size 762 Byte
Status CE

Compile Error

./Main.cpp:1:1: error: ‘def’ does not name a type
 def solve( s , c ):
 ^
./Main.cpp:33:1: error: ‘s’ does not name a type
 s = input()
 ^