1935A - Entertainment in MAC - CodeForces Solution


constructive algorithms strings

Please click on ads to support us..

Python Code:

import sys
import math
import bisect
from sys import stdin,stdout
from math import gcd,floor,sqrt,log
from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br

sys.setrecursionlimit(100000000)

inp    =lambda: int(input())
strng  =lambda: input().strip() jn     =lambda x,l: x.join(map(str,l)) strl   =lambda: list(input().strip()) mul    =lambda: map(int,input().strip().split()) mulf   =lambda: map(float,input().strip().split()) seq    =lambda: list(map(int,input().strip().split())) 
ceil   =lambda x: int(x) if(x==int(x)) else int(x)+1
ceildiv=lambda x,d: x//d if(x%d==0) else x//d+1

flush  =lambda: stdout.flush()
stdstr =lambda: stdin.readline() stdint =lambda: int(stdin.readline())
stdpr  =lambda x: stdout.write(str(x)) 
mod=1000000007

def decimal_to_binary(decimal_num):
	binary_str = format(int(decimal_num), 'b')
	return binary_str

def print_list(nums):
    s = ' '.join(map(str, nums))
    return s.strip()

def sort_string(word, flag):
        if flag == True:
        sorted_word = ''.join(sorted(word, key=str.lower))
        if flag == False:
        sorted_word = ''.join(sorted(word))
    return sorted_word

def print_single_line(arr):
    print(*arr)
    return

def factors_of_a_number(n):
    result = []
    for i in range(1, math.ceil(n**0.5) + 1):
        if n % i == 0:
            if n // i == i:
                result.append(i)
            else:
                result.append(i)
                result.append(n // i)
        return result

def prime_factors(n):
    result = []
        while n % 2 == 0:
        result.append(2)
        n = n / 2
            for i in range(3,int(math.sqrt(n))+1,2):
                while n % i== 0:
            result.append(i)
            n = n / i
            if n > 2:
        result.append(n)
    return result






if __name__ == "__main__":
    t = inp()
    for _ in range(t):
        n = inp()
        s = input()
        m = len(s)
        flag = True 
        left, right = 0, m - 1
        while left < right:
            if s[left] < s[right]:
                break
            elif s[left] > s[right]:
                flag = False
                break
            else:
                left += 1
                right -= 1
        
        if flag == True:
                        print(s)         else:
            result = s[::-1] + s
            print(result)
            


Comments

Submit
0 Comments
More Questions

45A - Codecraft III
1242A - Tile Painting
1663E - Are You Safe
1663D - Is it rated - 3
1311A - Add Odd or Subtract Even
977F - Consecutive Subsequence
939A - Love Triangle
755A - PolandBall and Hypothesis
760B - Frodo and pillows
1006A - Adjacent Replacements
1195C - Basketball Exercise
1206A - Choose Two Numbers
1438B - Valerii Against Everyone
822A - I'm bored with life
9A - Die Roll
1430B - Barrels
279B - Books
1374B - Multiply by 2 divide by 6
1093B - Letters Rearranging
1213C - Book Reading
1468C - Berpizza
1546B - AquaMoon and Stolen String
1353C - Board Moves
902A - Visiting a Friend
299B - Ksusha the Squirrel
1647D - Madoka and the Best School in Russia
1208A - XORinacci
1539B - Love Song
22B - Bargaining Table
1490B - Balanced Remainders