[알고리즘]/BOJ

[백준/Python] 기초 10제 - Day4

개발새발주발 2023. 2. 16. 20:24
728x90

1.

17094

 

17094번: Serious Problem

2의 등장횟수가 더 많다면 2를 출력하고, e의 등장횟수가 더 많다면 e를 출력한다. 등장횟수가 같다면 "yee"를 출력한다. (큰 따옴표 제외)

www.acmicpc.net

n = int(input())
str=input()


if str.count('2') > str.count('e'):
    print(2)
elif str.count('2') < str.count('e'):
    print('e')
else:
    print('yee')

2.

15000

 

15000번: CAPS

Earth is under attack! Messages need to be sent to the Earth Defense Force (EDF) that makes clear that the situation is dire. The EDF’s strongest forces consist of mechs (huge bipedal robots) that are piloted by Japanese teenagers. To make sure that the

www.acmicpc.net

print(input().upper())

한줄짜리 정답 ~ ! 

 

 

3.

1267번

 

1267번: 핸드폰 요금

동호가 저번 달에 이용한 통화의 개수 N이 주어진다. N은 20보다 작거나 같은 자연수이다. 둘째 줄에 통화 시간 N개가 주어진다. 통화 시간은 10,000보다 작거나 같은 자연수이다.

www.acmicpc.net

n = int(input())

time = list(map(int,input().split()))
y,m = 0,0

for i in time:
    y += (i//30 +1)*10
    m += (i//60 +1)*15



if y<m:
        print("Y",y)
elif y>m :
        print("M",m)
else :
        print("Y M",y)

 

4.

19698번

 

19698번: 헛간 청약

$1 \le N, W, H, L \le 1,000$

www.acmicpc.net

n,w,h,l = map(int,input().split())

max_w = w//l
max_h = h//l

max_cow = max_w * max_h

print(min(max_cow, n))

 

5.

2511번

 

2511번: 카드놀이

첫 번째 줄에는 게임이 끝난 후, A와 B가 받은 총 승점을 순서대로 빈칸을 사이에 두고 출력한다. 두 번째 줄에는 이긴 사람이 A인지 B인지 결정해서, 이긴 사람을 문자 A 또는 B로 출력한다. 만약

www.acmicpc.net

a= list(map(int,input().split()))
b= list(map(int,input().split()))

a_point,b_point = 0,0
winner = ''

for i in range(10):
    if a[i]>b[i]:
        a_point+=3
        winner='A'
    elif a[i]<b[i] :
        b_point+=3
        winner='B'
    else:
        a_point+=1
        b_point+=1


print(a_point,b_point)
if a_point>b_point:
    print('A')
elif a_point<b_point:
    print('B')
else:
    if a_point == 10 and b_point ==10:
        print('D')
    else:
        print(winner)

3트걸려서 맞은 문제 .. 

문제 제대로 안읽은듯 ..

조건이 생각보다 까다로워서 계속 추가하다보니 몇번에 걸쳐서 정답을 제출하게 되었다 .. 

 

 

6.

1350번

 

1350번: 진짜 공간

첫째 줄에 파일의 개수 N이 주어진다. N은 50보다 작거나 같은 자연수이다. 둘째 줄에는 파일의 크기가 공백을 사이에 두고 하나씩 주어진다. 파일의 크기는 1,000,000,000보다 작거나 같은 음이 아닌

www.acmicpc.net

n = int(input())
file =list(map(int,input().split()))
cluster = int(input())

mul = 0

total = 0
for i in file:
    mul+=i // cluster
    if i % cluster !=0 :
        mul+=1
    else:
        mul+=0

print(cluster * mul)

생~각보다 어렵지 않은 문제였다. 

 

7.

2576번

 

2576번: 홀수

7개의 자연수가 주어질 때, 이들 중 홀수인 자연수들을 모두 골라 그 합을 구하고, 고른 홀수들 중 최솟값을 찾는 프로그램을 작성하시오. 예를 들어, 7개의 자연수 12, 77, 38, 41, 53, 92, 85가 주어지

www.acmicpc.net

total = 0
mini =100
for i in range(7):
    n=int(input())

    if n%2 ==1 :
        total +=n
        mini = min(n, mini)

if total ==0 :
    print(-1)
else:
    print(total)
    print(mini)

 

8.

1551번

 

1551번: 수열의 변화

첫째 줄에 수열의 크기 N과 K가 주어진다. N은 20보다 작거나 같은 자연수이고, K는 0보다 크거나 같고, N-1보다 작거나 같은 정수이다. 둘째 줄에는 수열이 ‘,’로 구분되어 주어진다. 수열을 이루

www.acmicpc.net

개인적으로 시간이 많이 걸렸던 문제  ..

n,k = map(int,input().split())

seq = list(map(int,input().split(',')))

for i in range(k):

    ans = [seq[j+1]-seq[j] for j in range(len(seq)-1)]
    seq = ans
print(*seq, sep=',')

문제를 눈을 씻고 보자 젭 알 

 

 

9.

11094번

 

11094번: 꿍 가라사대

영어공부를 열심히 하고 있는 꿍이 대학교MT에 놀러가서 친해지고 싶은 후배들과 Simon Says 게임을 하려고 한다. "Simon Says" 게임의 룰은 간단하다. 만약 어떤 사람이 "Simon says"라고 말한 후 어떤 지

www.acmicpc.net

n =int(input())

for i in range(n):
    str = input()
    if 'Simon says' in str:
        new_str = str.replace('Simon says','')
        print(new_str)
    else:
        continue

파이썬 문자열에서 특정 문자열을 삭제하는 방법이 유용하게 쓰인다. 

** 참고 

 

Python - 문자열에서 특정 문자 제거, 3가지 방법

파이썬에서 문자열 안의 특정 문자를 제거하는 방법을 소개합니다. replace(A, B)는 문자열의 A를 모두 B로 변경합니다. 이 함수를 이용하여 특정 문자를 ''으로 변경하여 제거할 수 있습니다. sub(rege

codechacha.com

 

 

10.

2562번

 

2562번: 최댓값

9개의 서로 다른 자연수가 주어질 때, 이들 중 최댓값을 찾고 그 최댓값이 몇 번째 수인지를 구하는 프로그램을 작성하시오. 예를 들어, 서로 다른 9개의 자연수 3, 29, 38, 12, 57, 74, 40, 85, 61 이 주어

www.acmicpc.net

num = [int(input()) for i in range(9)]

print(max(num))
print(num.index(max(num))+1)

** 잊지말기 

배열에서 특정 값 index찾는 방법 -> 배열.index(찾으려는 원소)