Codejam 1A Round 2022. Task 1
Python Only
T=int(input())
for t in range(T):
S=input()
NS=''; i=0; temp=''
while i < len(S)-1:
if (len(set(S[i:])) == 1) and (len(S[i:]) > 1):
NS+=S[i:-1]
break
else:
if S[i+1] > S[i]:
NS+=2*temp+2*S[i]
temp=''
elif S[i+1] < S[i]:
NS+=temp+S[i]
temp=''
else:
temp+=S[i]
i+=1
print('Case #{}: {}'.format(t+1,NS+S[-1]))
def gen_first(S):
i=0; temp=''
while i < len(S)-1:
if (len(set(S[i:])) == 1) and (len(S[i:]) > 1):
yield S[i:-1]
break
else:
if S[i+1] > S[i]:
yield 2*temp+2*S[i]
temp=''
elif S[i+1] < S[i]:
yield temp+S[i]
temp=''
else:
temp+=S[i]
i+=1
yield S[-1]
T=int(input())
for t in range(T):
S=input()
NS=''.join(gen_first(S))
print('Case #{}: {}'.format(t+1,NS))
xxxxxxxxxx
def twice_ones(
T=[1,2,3],
S=input_box('PEEL\nAAAAAAAAAA\nCODEJAMDAY',
type=str,label='S',width=20,height=3)):
S=str(S).split('\n'); s=S[T-1]
print('input: ',s)
ns=''; i=0; temp=''
while i < len(s)-1:
if (len(set(s[i:])) == 1) and (len(s[i:]) > 1):
ns+=s[i:-1]
break
else:
if s[i+1] > s[i]:
ns+=2*temp+2*s[i]
temp=''
elif s[i+1] < s[i]:
ns+=temp+s[i]
temp=''
else:
temp+=s[i]
i+=1
print('Case #{}: {}'.format(T,ns+s[-1]))
No comments:
Post a Comment