본문 바로가기
python-algorithm

백준 27541 末尾の文字 (Last Letter)

by 무적김두칠 2023. 2. 24.

https://www.acmicpc.net/problem/27541

 

27541번: 末尾の文字 (Last Letter)

葵が見た文字列 JOI の末尾の文字は G でないので,葵は末尾に文字 G を付け加えた文字列 JOIG を思い浮かべる.そのため,JOIG を出力する.

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
def sol(n, s) -> str:
    if s[-1== 'G':
        return s[:n - 1]
    else:
        return s + 'G'
 
 
if __name__ == '__main__':
    n = int(input())
    s = str(input())
    print(sol(n, s))
 
cs

슬라이싱을 활용해서 주어진 문자열의 마지막 글자가 'G'로 끝나는지 확인하면 됩니다.
Using slice, Check whether the string ends 'G'

반응형

'python-algorithm' 카테고리의 다른 글

백준 26471 Farma  (0) 2023.02.24
백준 9771 Word Searching  (0) 2023.02.24
leetcode 232. Implement Queue using Stacks  (0) 2023.02.23
leetcode 739. Daily Temperatures  (0) 2023.02.23
leetcode 316. Remove Duplicate Letters  (1) 2023.02.23

댓글