1. 회문 문자열 검사

Screenshot 2023-08-26 at 5.59.21 PM.png

Screenshot 2023-08-26 at 6.00.03 PM.png

import sys 
sys.stdin = open("input.txt", 'r')
n = int(input())
for i in range(n):
		s = input()
		s = s.upper()
		size = len(s)
		for j in range(size//2):
				if s[j] != s[-1-j]:
						print("#%d NO" %(i+1))
						break
				else: 
						print("#%d YES"  %(i+1))
#1 YES #2 NO #3 YES #4 NO #5 YES
sys.stdin = open("input.txt", 'r')
n = int(input())
for i in range(n):
		s = input()
		s = s.upper()
		if s ==[::-1]:  # reverse 
				print("#%d YES"  %(i+1))
		else:
				print("#%d NO" %(i+1))
				break
  1. 숫자만 추출
import sys
sys.stdin = open("input.txt", "r")
s = input()
res = 0
for x in s:
		print(x, end = ' ')
		if x.isdecimal():
			 res = res*10 + int(x)
print(res)
cnt = 0
for i in range(1, res+1):
		if res%i == 0:
			 cnt += 1
print(cnt)
  1. 카드 역배치
a, b = map(int, input().split())
a, b = b, a # swap
a = list(range(21)) # 0 1 2 3 4 ... 19 20

for _ in range(10): # 변수 없이 그냥 반복 >> 시간 단축
		s, e = map(int, input().split())
		for i in range((e-s+1)//2):
				a[s+i], a[e-i] = a[e-i], a[s+i]
a.pop(0) # 맨 앞자리 pop
for x in a:
		print(x, end = ' ')
  1. 두 리스트 합치기

Screenshot 2023-08-26 at 7.07.19 PM.png

n = int(input())
a = list(map(int, input().split())
m = int(input())
b = list(map(int, input().split())
p1 = p2 = 0
c = []

# for p1, p2 in range(len(a), len(b)):
while p1<n and p2<m:
		if a[p1] <= b[p2]:
				c.append(a[p1])
				p1+= 1
		else:
			  c.append(b[p2])
				p2+=1
if p1 < n: # 한 리스트 모두 끝나고 하나만 남았을 때 그냥 그대로 slicing
		c = c + a[p1:] 
if p2 < m:
		c = c + b[p2:]
for x in c:
		print(x, end = ' ')
  1. 수의 합 ⭐️

Screenshot 2023-08-26 at 8.04.32 PM.png

Screenshot 2023-08-26 at 8.05.49 PM.png

Screenshot 2023-08-26 at 8.06.14 PM.png

Screenshot 2023-08-26 at 8.06.36 PM.png

Screenshot 2023-08-26 at 8.07.19 PM.png

Screenshot 2023-08-26 at 8.07.41 PM.png

n, m = map(int, input().split())
a = list(map(int, input().split())
lt = 0
rt = 1
tot = a[0]
cnt = 0
while True:
		if tot < m:
				if rt < n:
						tot += a[rt]
						rt += 1
				else:
						break
			elif tot == m:
					cnt += 1
					tot -= a[lt]
					lt += 1
			else:
					tot -= a[lt]
					lt += 1
print(cnt)