2022. 9. 16. 07:16ㆍ백준 문제 풀이/파이썬
1)1330 ( △ )
>오답
a,b = input().split()
if a>b :
print(">")
elif a<b:
print("<")
else:
print("==")
▶복수의 int값을 입력 받을때는 map(int,input().split())을 해준다.
>정답(구글링)
a,b = map(int,input().split())
if a>b :
print(">")
elif a<b:
print("<")
else:
print("==")
2)9498( ㅇ )
>정답
a = int(input())
if a >= 90 :
print("A")
elif a>= 80:
print("B")
elif a>= 70:
print("C")
elif a>= 60:
print("D")
else:
print("F")
▶컴파일에러 (들여쓰기 주의)
아무래도 elif를 쓸 때 앞으로 빠짝 댕겨야할것같다. 띄어쓰니까 바로 컴파일 오류 나오는거보니 확실히 이것이 이유가 맞다. if와 elif, else는 줄을 맞춰야함.
3)2753( ㅇ )
a=int(input())
if (a%4==0 and a%100!=0) or a%400==0:
print(1)
else:
print(0)
▶if 문안에 중복으로 and와 or도 쓸 수 있음. 괄호도 쓸 수 있다. 또 if문에서 같지않다는 !=써준다.
배수찾기 할때는 %해서 나머지가 0인지 확인해주면 끝.
4)14681( ㅇ )
>오답
a = int(input())
b = int(input())
if a > 0 and b > 0 :
print(1)
elif a < 0 and b > 0 :
print(2)
elif a < 0 and b > 0 :
print(3)
else:
print(4)
▶if문내에서 ','사용 > and로 변경
elif문 들여쓰기(빠짝댕겨야함)
치명적인 실수 : 3사분면에 올 값이 b<0이되어야하는데 b>0이라고 함.
>정답
a = int(input())
b = int(input())
if a > 0 and b > 0 :
print(1)
elif a < 0 and b > 0 :
print(2)
elif a < 0 and b < 0 :
print(3)
else:
print(4)
5)2884( x )
>오답
가)분은 정상적으로 나온다. 다만 시간 값조차 제대로 안나옴.
(h,m)=list(map(int,(input().split())))
if m < 45 :
print((h-1) and print((m+60)-45))
else :
print(h) and print(m-45)
나) 분을 정상적으로 나오게했고 시간이 문제다. 시간을 위로 올리려고 별 노력을 다하는 중
h,m=list(map(int,(input().split())))
if m<45 :
print((h-1, end="")
print((m+60)-45))
else :
print(h, end="")
print(m-45)
다)계산은 맞게 했는데 00시로 설정했을 때 값을 못구하겠다.
h,m = map(int,input().split())
if m < 45 :
print(h-1, m+15)
else:
print(h, m-45)
>정답
h,m = map(int,input().split())
if m > 44 :
print(h, m-45)
elif m < 45 and h > 0:
print(h - 1, m + 15)
else:
print(23, m+15)
▶H가 1미만일 경우를 조건으로 추가해주고 무조건 23이 나오게끔 출력
6) 2525(x)
>오답
가)개떡같은 코드
a,b = map(int,input().split())
c =int(input())
if b<30 and c<60:
print(a,b+c)
elif b<30 and c>=60:
print(a+1,b+c-60)
elif b>30 and c < 60:
print(a+1, b+c-60)
else :
print(a+1, b+c-60)
나)2프로 부족한 코드
a,b = map(int,input().split())
c =int(input())
if b+c < 60:
print(a,b+c)
elif b+c > 60:
print(a+1,b+c-60)
else:
print(a+1, 0)
▶여기서 60분이 되었을때 0으로 넘어가게 해줘야하고, 24시가 되었을때 0으로 넘어가게 해야한다.
17 40 / 80 > 18 60 나오고 23 48 / 25 > 24 13 나옴.
다)1프로 부족한 코드
나 코드에서 조건 두개 추가해줌. 우선 b+c == 60 해주니까 120인 경우는 계속 무시가 됐음. 그래서 60으로 나눴을 때 나머지가 0인 것으로 넣어주고 시간에 그 몫만큼을 더해주는 것으로 했음.
a,b = map(int,input().split())
c =int(input())
if b+c < 60:
print(a,b+c)
elif b+c > 60 :
print(a+1,b+c-60)
elif (b+c)%60 == 0:
print(a+((b+c)//60), 0)
라) 0.5프로 부족한 코드
우선 라코드로 실행하면 파이참에서는 정상적으로 작동되는데 백준에서는 틀린 문제라고 나온다.
a,b = map(int,input().split())
c =int(input())
if a != 23 and b+c < 60:
print(a,b+c)
elif a != 23 and b+c > 60:
print(a+1,b+c-60)
elif a != 23 and (b+c)%60 == 0:
print(a+((b+c)//60), 0)
elif a == 23 and (b+c) > 60:
print(0 , (b+c)-60)
else :
print(a, (b+c))
>정답(권기현 튜터님)
a,b = map(int,input().split())
c =int(input())
a += c//60
b += c%60
if b>= 60 :
a += 1
b -= 60
if a>=24 :
a -= 24
print(a,b)
7)2480( x )
>오답
1)
a,b,c=list(map(int,input().split()))
if a==b==c:
print(10000+a*1000)
elif a==b!=c:
print(1000+a*100)
else:
print(max(a))
▶예제 336이랑 222는 정상 출력, 625는 출력 안됨. 우선 max(a)에 100도 안곱했고 보니 max(a)가 아니라 max(a,b,c)를 해줘야 숫자가 다 들어갈 것 같다.
2)
a,b,c=list(map(int,input().split()))
if a==b==c:
print(10000+a*1000)
elif a==b!=c:
print(1000+a*100)
else:
print(max(a,b,c)*100)
3)파이참에서는 정상 작동...
a,b,c=list(map(int,input().split()))
A=(a,b,c)
#A=[a,b,c]
if a==b==c:
print(10000+a*1000)
elif a==b!=c or a!=b==c or c==a!=b :
print(1000+a*100)
else:
print(max(A)*100)
>정답(구글링 + 셀프)
a,b,c=list(map(int,input().split()))
if a==b==c:
print(10000+a*1000)
elif a==b :
print(1000+a*100)
elif b==c :
print(1000+b*100)
elif a==c :
print(1000+c*100)
else:
print(max(a,b,c)*100)
▶elif 쓸때 굳이 하나 안에 다 넣으려고 할 필요 없다. 간과했던 것은 b==c일때 a*100을 출력해줬는데 이것이 오류였고 다 나눠서 식을 푸니 금방 풀린다. 멋있지는 않은 코드인데 좀 더 찾아봐야겠다.
'백준 문제 풀이 > 파이썬' 카테고리의 다른 글
| [백준문제풀이] 3단계_반복문 (1) | 2022.09.20 |
|---|---|
| [백준 문제풀이/파이썬] 1단계_입출력과 사칙연산 (0) | 2022.09.16 |
| [백준문제풀이/파이썬] 4단계_1차원배열 (0) | 2022.09.15 |
| [백준파이썬] 7단계_기본 수학 1 (0) | 2022.09.14 |