일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 프로그래머스
- reduce()
- replacesubrange()
- MVC
- IOS
- prefix()
- xib
- 코드업 파이썬 기초 100제
- Info.plist
- zip()
- 클론코딩
- uikit
- uisearchbar
- 대문자소문자
- Segue
- 싱글톤
- 라이징캠프
- String()
- API
- swift
- github
- joined()
- 코딩테스트
- alamofire
- components()
- 알고리즘
- suffix()
- Autolayout
- GIT
- tableView
- Today
- Total
Daeng iOS
[코드업 CodeUp] Python 기초 100제 (6031~6040) 본문
[코드업 CodeUp] Python 기초 100제 (6031~6040)
U_Daeng 2022. 2. 8. 01:48[문제집 링크]
https://codeup.kr/problemsetsol.php?psid=33
문제집 / Python 기초 100제
codeup.kr
[깃허브]
https://github.com/yujeong-kwon/Coding-test/tree/master/Codeup
GitHub - yujeong-kwon/Coding-test
Contribute to yujeong-kwon/Coding-test development by creating an account on GitHub.
github.com
6031번은 값변환, 6032번부터 6040번은 산술연산이었다.
#6031 - 정수 입력받아 유니코드 문자로 변환하기
10진 정수 1개를 입력받아 유니코드로 출력
내 풀이
import sys
input = sys.stdin.readline
num = int(input().rstrip())
print(chr(num))
모범 풀이
c=input()
c=int(c)
print(chr(c))
chr()로 정수 값을 유니코드 문자(chracter)로 바꿔 출력한다.
chr()는 정수 값 -> 문자, ord()는 문자 -> 정수 값 형태로 바꿔주는 기능을 한다.
#6032 - 정수 1개 입력받아 부호 바꾸기
입력된 정수의 부호를 바꿔 출력
내 풀이
import sys
input = sys.stdin.readline
print(-int(input().rstrip()))
모범 풀이
a=int(input())
print(-a)
단항(unary) 연산자인 -(negative)를 변수 앞에 붙이면 부호가 반대인 값이 된다.
#6033 - 문자 1개 입력받아 다음 문자 출력하기
문자 1개를 입력받아 그 다음 문자를 출력
내 풀이
import sys
input = sys.stdin.readline
x = ord(input().rstrip())
print(chr(x+1))
모범 풀이
n1=input()
n2=ord(n1)+1
s=chr(n2)
print(s)
다음 문자를 출력하기 위해 ord()를 이용해 정수 값으로 바꿔 주고 +1을 한 다음 chr()을 이용해 다시 문자로 바꿔준다.
#6034 - 정수 2개 입력받아 차 계산하기
정수 2개(a, b)를 입력받아 a에서 b를 뺀 차를 출력
내 풀이
import sys
input = sys.stdin.readline
a, b = map(int,input().rstrip().split())
print(a-b)
모범 풀이
a, b = input().split()
c = int(a)-int(b)
print(c)
전에도 나온 것 같긴한데 여기서 map()에 대해 정리하고 넘어가자면, 리스트 같은 반복 가능한 객체에 대해 각각의 요소들을 지정된 함수로 처리해주는 함수다!! 위 풀이에선 입력받은 변수들을 int형으로 변환하기 위해 사용했다.
#6035 - 실수 2개 입력받아 곱 계산하기
실수 2개(f1, f2)를 입력받아 곱을 출력
내 풀이
import sys
input = sys.stdin.readline
a, b = map(float,input().rstrip().split())
print(a*b)
모범 풀이
f1, f2 = input().split()
m = float(f1)*float(f2)
print(m)
#6036 - 단어 여러 번 출력하기
단어와 반복 횟수를 입력받아 여러 번 출력
내 풀이
import sys
input = sys.stdin.readline
string = list(input().rstrip().split())
print(string[0]*int(string[1]))
모범 풀이
w, n = input().split()
n=int(n)
print(w*n)
list()는 리스트로 변환해주는 함수다. 근데 생각해보니 문자열을 굳이 list로 바꾸지 않아도 된다는게 생각났다..!
아니면 코드업의 풀이 처럼 입력 받은 두 문자를 split()으로 쪼개서 저장해서 사용해도 된다.
#6037 - 문장 여러 번 출력하기
반복 횟수와 문장을 입력받아 여러 번 출력
내 풀이
import sys
input = sys.stdin.readline
n = input().rstrip()
s = input().rstrip()
print(s*int(n))
모범 풀이
n = input()
s = input()
print(int(n)*s)
#6038 - 정수 2개 입력받아 거듭제곱 계산하기
정수 2개(a, b)를 입력받아 a를 b번 곱한 거듭제곱을 출력
내 풀이
import sys
input = sys.stdin.readline
a, b = map(int,input().rstrip().split())
print(a**b)
모범 풀이
a, b = input().split()
c = int(a)**int(b)
print(c)
거듭제곱을 계산하기 위한 연산자는 ** 이다!
#6039 - 실수 2개 입력받아 거듭제곱 계산하기
실수 2개(f1, f2)를 입력받아 f1을 f2번 거듭제곱한 값을 출력
내 풀이
import sys
input = sys.stdin.readline
a, b = map(float,input().rstrip().split())
print(a**b)
모범 풀이
f1, f2 = input().split()
f3 = float(f1)**float(f2)
print(f3)
#6040 - 정수 2개 입력받아 나눈 몫 계산하기
정수 2개(a, b)를 입력받아 a를 b로 나눈 몫을 출력
내 풀이
import sys
input = sys.stdin.readline
a, b = map(int,input().rstrip().split())
print(a//b)
모범 풀이
a, b = input().split()
print(int(a)//int(b))
몫을 구하기 위해선 //(floor division)를 사용한다.
'알고리즘 & 코딩테스트 > CodeUp : Python 기초 100제' 카테고리의 다른 글
[코드업 CodeUp] Python 기초 100제 (6051~6060) (0) | 2022.08.26 |
---|---|
[코드업 CodeUp] Python 기초 100제 (6041~6050) (0) | 2022.03.05 |
[코드업 CodeUp] Python 기초 100제 (6021~6030) (0) | 2022.02.07 |
[코드업 CodeUp] Python 기초 100제 (6011~6020) (0) | 2022.02.05 |
[코드업 CodeUp] Python 기초 100제 (6001~6010) (0) | 2022.01.27 |