| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
- algorithm
- 프로그래머스
- level1
- 리스트
- 짝수
- 최대공약수
- 11004
- 11652
- 알고리즘
- valueof
- PaaS
- 웹 서버
- aws
- java
- 프로젝트 생성
- 데이터타입
- 문자열 숫자 변환
- 자료형
- IntelliJ
- Python
- SaaS
- 유클리드 호제법
- 온프레미스
- parseInt
- INT
- 최대공배수
- 홀수
- 백준
- 2진수
- IaaS
- Today
- Total
목록Algorithm (39)
Ga0Lee
코드 import sys a, b, c, d = input().split() num1 = "" num2 = "" num1 += a+b num2 += c+d print(int(num1) + int(num2)) 입출력
코드 import sys str = sys.stdin.readline().rstrip("\n") ROT13 = "" for i in str: if 'a'
코드 import sys str = sys.stdin.readline().rstrip("\n") print(len(str)) 엔터 입력을 무시해줘야 정확한 단어 길이가 나온다. rstrip("\n")가 없는 경우 아래 단어의 출력 값이 9로 나온다. 입출력
ASCII CODE 값 'A' ~ 'Z' : 65 ~ 90 'a' ~ 'z' : 97 ~ 122 0 ~ 9 : 48 ~ 57 코드 import sys while True: str = sys.stdin.readline().rstrip("\n") if not str : break alphabet =[0] * 4 for i in str: if ord(i) > 96 and ord(i) 64 and ord(i) 47 and ord(i) < 58 : alphabet[2] += 1 elif i == " " : alphabet[3] += 1 print(*alphabet) str = ..
알파벳 개수 찾는 문제와 거의 동일하다. 리스트를 -1로 초기화하고 해당 알파벳의 인덱스에 입력받은 알파벳의 인덱스 값을 넣어주면 된다. 코드 import sys alphabet =[-1] * 26 str = sys.stdin.readline().rstrip() for i in range(len(str)): if(alphabet[ord(str[i]) - 97] == -1 ): alphabet[ord(str[i]) - 97] = i print(*alphabet) 입출력
알파벳 하자마자 아스키 코드가 생각났다. 파이썬에선 아스키코드 값을 반환하는 내장함수 ord()가 존재한다. 틀린 코드 import sys alphabet =[0] * 26 str = sys.stdin.readline() for i in str: alphabet[ord(i) - 97] += 1 print(*alphabet) 입출력 문자열을 입력받을 때 sys.stdin.realine().rstrip()으로 바꿔주니 문제가 해결됐다. 코드 import sys alphabet =[0] * 26 str = sys.stdin.readline().rstrip() for i in str: alphabet[ord(i) - 97] += 1 print(*alphabet) 입출력 아 그리고 처음엔 리스트를 공백으로 구분하..
큐와 비슷하지만 덱은 양쪽에서 push, pop이 가능하다. 코드 import sys n = int(input()) deque = [] for i in range(n): command = sys.stdin.readline().split() if command[0] == 'push_front' : deque.insert(0,command[1]) elif command[0] == 'push_back' : deque.append(command[1]) elif command[0] == "pop_front" : if len(deque) == 0 : print(-1) else : print(deque.pop(0)) elif command[0] == "pop_back" : if len(deque) == 0 : pri..
queue 는 선입선출이라는 것을 기억하고 풀었다. 코드 import sys n = int(sys.stdin.readline()) queue = [] for i in range(n): command = sys.stdin.readline().split() if command[0] == 'push' : queue.insert(0,command[1]) elif command[0] == 'pop' : if len(queue) == 0: print(-1) else : print(queue.pop()) elif command[0] == 'size' : print(len(queue)) elif command[0] == 'empty' : if len(queue) == 0 : print(1) else : print(0)..
Stack을 pop 했을 때 top의 값이 감소하는 것을 이용하여 풀었습니다. 코드 import sys n = int(sys.stdin.readline()) for i in range(n) : stack = sys.stdin.readline() top = 0 for j in stack: if j == '(' : top += 1 elif j == ')' : top -= 1 if top 0 : print('NO') elif top == 0: print('YES') 입출력
코드 import sys n = int(sys.stdin.readline()) stack = [] for i in range(n): command = sys.stdin.readline().split() if command[0] == 'push': stack.append(command[1]) elif command[0] == 'pop': if len(stack) == 0: print(-1) else: print(stack.pop()) elif command[0] == 'size': print(len(stack)) elif command[0] == 'empty': if(len(stack)==0): print(1) else : print(0) elif command[0] == 'top': if len(stac..