백준 파이썬 기초 문제 풀기1

Haein Lee·2022년 9월 23일
0

싄나게 백준 문제 풀기 🥲

입출력
1. #2557 hello world

def hello():
    print('Hello World!')
hello()
  1. #10869 사칙연산
a, b = map(int , input().split())

print(a+b) # 덧셈
print(a-b) # 뺄셈
print(a*b) # 곱셈
print(a//b) # 몫
print(a%b) # 나머지
  1. #2588 곱셈
a=int(input())
b=input()

axb2 = a*int(b[2])
axb1= a*int(b[1])
axb0 = a*int(b[0])
axb=a*int(b)

print(axb2, axb1, axb0,axb)

조건문
4. #9498 시험성적

score= int(input())

if score >= 90 :
    print('A')
elif score >=80:
    print('B')
elif score >=70:
    print('C')
elif score >=60:
    print('D')
else :
    print('F')
  1. #2753 윤년
year= int(input())

if ((year%4 ==0) and (year%100 !=0 )) or (year%400 ==0 ) :
    print('1')
else:
    print('0')
  1. #1085 직사각형에서 탈출
x, y, w, h = map(int, input().split())
print(min(x,y,w-x, h-y))

반복문
7. #2739 구구단

n= int(input())
for i in range(1, 10):
    print(n,'*',i,'=',n*i)
  1. #10950 a+b 맞추기
t= int(input())
for _ in range(t):
    a, b = map(int,input().split())
    print(a+b)
  1. #2438 별찍기 -1
n = int(input())
for i in range(1, n+1): # 1부터 n+1까지
    print('*' * i )
  1. #10871 x보다 작은 수
n, x = map(int,input().split())
num = list(map(int,input().split()))
for i in range(n):
    if num[i]<x:
        print(num[i], end=" ") #end="" 이게 있어야 답이 옆으로 나옴
#num 변수를 list로 만들어서 int로 집어 넣는다 
#for 문 안에 n을 집어 넣어서 

<자료구조와 배열>
리스트와 튜플을 사용
배열- 묶음 단위로 값을 저장하는 (객체가 저장이 되고 저장된 객체 하나하나 를 원소)
<연습 문제>
-시퀀스 원소의 최댓값 구하기-

from typing import Any, Sequence


def max_of(a: Sequence) -> Any:
    maximum = a[0]
    for i in range(1, len(a)):
        print(len(a))
        if a[i] > maximum:
            maximum = a[i]
        return maximum

if __name__=='__main__':
    print('배열의 최댓값을 구합니다.')
    num= int(input('원소의 수를 입력:'))
    x = [None]*num
    
    # 여기서 None이란..? null 값 값의 부재를 나타낼때 쓴댕 
    
    for i in range(num):
        x[i]= int(input(f'x[{i}]값을 입력하세요:'))

    print(f'최댓값은 {max_of(x)} 입니다')

배열
11. #2562 최대값

num_list =[]
for i in range(9):
    num_list.append(int(input()))

print(max(num_list))
print(num_list.index(max(num_list))+1)
  1. #8958 ox quize
a= int(input()) #숫자 하나를 입력
for i in range(a): #숫자만큼 입력할수있음

    ox_list = list(input())
    score = 0
    sum_score = 0 # 새로운 ox리스트를 입력 받으면 점수 합계를 리셋함
    for ox in ox_list: #0이 연속 되어있으면 숫자가 늘어남 
        if ox =='o':
            score +=1 
            sum_score += score #다 더함
        else:
            score = 0
    print(sum_score)#o,x를 입력하면 출력이 됨
 

#숫자 하나를 입력
#숫자만큼 입력할수있음
#0이 연속 되어있으면 숫자가 늘어남 
#다 더함
#o,x를 입력하면 출력이 됨
N = int(input())

for i in range(N):
    a = input()
    score = 0
    sumScore = 0
    for j in a:
        if j == 'O':
            score += 1
        else:
            score = 0
        sumScore += score
    print(sumScore)
  1. #4344 평균은 넘겠지...
c=int(input()) # 테스트케이스 개수
for i in range(c): 
    score=list(map(int,input().split())) #점수 들 
    c=0 
    for n in score[1:]: #두번쨰부터 끝까지 
        avg=sum(score[1:])/score[0] #점수들더하고 맨앞 숫자로 나눈다 
        if n> avg: 
            c+=1 
    rate = c/score[0]*100 
    print('{0:0.3f}%'.format(rate))
  1. #2577 숫자의 개수
#세개의 자연수 a,b,c가 있을때
#a*b*c 결과에 0~9 까지의 숫자가 몇번 쓰였는지
#함수 
a= int(input()) #한줄씩 입력
b= int(input())
c= int(input())

result = list(str(a*b*c)) #str을 이용해 문자열로 변환 하고 리스트로 문자의 요소를 가지게
for i in range(10):
    print(result.count(str(i)))

함수
15. #15596 정수 n개의 합

#정수 n개가 주어졌을떄, n개의 합을 구하는 함수를 작성
#???이건 진짜 모르겠는데?
def solve(a):
    total = 0
    for i in a:
        total += i
    return total

문자열
16. #11654 아스키코드

#입력하면 아스키코드로 출력하기 
asc = input() 
print(ord(asc))
  1. #2675 문자열 반복
s = int(input())
for i in range(s):
    count, word = input().split()
    for x in word:
        print(x*int(count), end="")
    print()
  1. #1152 단어의 개수
word = input().split()

print(len(word))
  1. #2908 상수
#숫자 두개 넣고 뒤집기 그리고 비교 
a,b = map(int,input().split())

a = int(str(a)[::-1])
b = int(str(b)[::-1])

print(a) if a>b else print(b)

profile
멋진 개발자가 될거야 :)

0개의 댓글