백준 파이썬 Today I Learn 2023.06.28
6/ 28 파이썬 공부
1. 백준 26530 Shipping
Your animals have begun producing products, and you’re honestly a little strapped for cash. Since you have far more animal byproducts than you know what to do with, you’ve decided to begin shipping them for extra money. Given the information in your shipping ledger, determine how much money you can expect to make.
The first line will contain a single integer n that indicates the number of data sets that follow. Each data set will start with a single integer x denoting how many items follow. The next x lines consist of a string, and integer, and a floating point number to two decimal places, representing the name of what was sold, the quantity, and the unit price of each item.
For each test case, output the amount of money you expect to make with all of the goods you sold, rounded to two decimal places.
>>>해석
당신의 동물은 제품을 생산하기 시작했으며 솔직히 현금이 약간 부족합니다.
당신은 당신이 필요한 양의 동물 부산물보다 훨씬 더 많은 동물 부산물이 있기 때문에 부 수입을 벌기 위해 배송을 시작하기로 결정했습니다. 배송 장부의 정보를 바탕으로 얼마나 많은 돈을 벌 수 있는지 결정하십시오.
첫 번째 줄에는 다음 데이터 세트의 수를 나타내는 단일 정수 n이 포함됩니다.
각 데이터 세트는 뒤에 오는 항목 수를 나타내는 단일 정수 x로 시작합니다.
다음 x 행은 문자열, 정수, 소수점 이하 두 자리까지의 부동 소수점 숫자로 구성되며 판매된 항목의 이름, 수량 및 각 항목의 단가를 나타냅니다.
각 테스트 케이스에 대해 판매한 모든 상품으로 예상되는 금액을 소수점 둘째 자리까지 반올림하여 출력하십시오.
>>>코드
for _ in range(int(input())):
result = 0
for i in range(int(input())):
name, count, price = input().split()
result += float(count) * float(price)
print('$%.2f' %(result))
2. 백준 26350 Good Coin Denomination
Different countries use different coin denominations. For example, the USA uses 1, 5, 10, and 25. A desirable property of coin denominations is to have each coin at least twice the amount of its previous coin in sorted order. For example, the USA denominations have this property, but the coin denominations {1, 5, 6} do not (6 is not at least twice 5).
Given the coin denominations, you are to determine if the set has the above property.
The first input line contains a positive integer, n, indicating the number of denomination sets to check. The sets are on the following n input lines, one set per line. Each set starts with an integer d (1 ≤ d ≤ 10), which is a count of various coin amounts in the set; this is followed by d distinct positive integers (each less than 1,000) giving each coin amount (assume the coin amounts are given in increasing order).
At the beginning of each test case, output “Denominations: v” where v is the input values. Then, on the next output line, print a message indicating whether or not the set has the above property. Leave a blank line after the output for each test case. Follow the format illustrated in Sample Output.
>>>해석
나라마다 다른 액면가를 사용합니다. 예를 들어 미국은 1,5,10,25를 사용합니다.
액면가는 각 동전이 작은 것부터 순서대로 이전 크기의 액면가보다 두 배 이상의 양을 가지는 것이 적합합니다.
미국의 액면가는 이 속성을 만족하지만, {1,5,6}은 이 속성을 만족하지 않습니다.
(6은 5의 두 배 보다 작기 때문입니다)
액면가가 주어지면 그 액면가가 위의 속성을 만족하는 지 확인해야합니다.
첫번째 줄에는 테스트 케이스의 개수가 양의 정수 n으로 주어집니다.
각 테스트 케이스는 n개의 줄에 걸쳐 한 줄에 하나씩 주어집니다.
각 테스트 케이스는 정수d(1 ≤ d ≤ 10)로 시작하며, 이는 액면가가 주어질 동전의 종류입니다.
그 다음에는 각 동전의 액면가가 d개의 양의 정수로 주어집니다(각각 1000 미만).
동전의 액면가는 오름차순으로 주어집니다.
각 테스트 케이스는 "Denominations: v"로 시작합니다. 여기서 v는 입력된 액면가들입니다.
다음 줄에 위 속성을 만족하는 지 여부를 나타내는 메시지를 출력합니다.
각 테스트 케이스가 끝나면 빈 줄을 하나 출력합니다. 기타 설명되지 않은 출력형식은 예제출력을 따릅니다.
>>>코드
for _ in range(int(input())):
l = list(map(int, input().split()))
c = 0
for i in range(1, len(l)-1):
if l[i] * 2 > l[i+1]:
c = 1
if c == 0:
print('Denominations:',*l[1::])
print('Good coin denominations!\n')
else:
print('Denominations:',*l[1::])
print('Bad coin denominations!\n')
3. 백준 25881 Electric Bill
To encourage customers to conserve energy (and protect the environment), the electric companies typically have a lower rate for the first 1000 kilowatt-hour (KWH) of electric usage and a higher rate for the additional usage (KWH is a derived unit of energy equal to 3.6 megajoules).
Given the rate (per KWH) for the first 1000 KWH usage, the rate (per KWH) for the additional usage, and a customer’s energy consumption, you are to determine the charges (bill) for the customer.
The first input line contains two integers (each between 2 and 20, inclusive), indicating the rate/KWH for the first 1000 KWH and the rate/KWH for the additional usage, respectively. The next input line contains a positive integer, n, indicating the number of customers to process. Each of the following n input lines contains an integer (between 1 and 50000, inclusive), indicating a customer’s energy consumption.
For each customer, print the energy consumption, followed by a space, followed by the charges.
>>>해석
고객이 에너지를 절약하고 환경을 보호하도록 장려하기 위해, 전기 회사는 일반적으로 처음 1000 KWH의 전기 사용량에 대해 더 낮은 요율을 적용하고 추가 사용량에 대해 더 높은 요율을 적용합니다.
(KWH는 에너지의 파생 단위입니다. 3.6메가줄과 같음).
처음 1000KWH 사용량에 대한 요율(KWH당), 추가 사용량에 대한 요율(KWH당) 및 고객의 에너지 소비량이 주어질 때, 고객에 대한 요금(청구서)을 결정해야 합니다.
첫째 줄에 2 이상 20 이하의 두 개의 정수가 주어집니다.
각각 처음 1000KWH에 대한 KWH당 요율과 추가 사용량에 대한 KWH당 요율을 나타냅니다.
둘째 줄에는 처리할 고객 수를 나타내는 양의 정수 n이 포함됩니다.
다음 n개의 줄에는 각각 고객의 에너지 소비량을 나타내는 1 이상 50000 이하의 정수가 주어집니다.
n개의 줄에 걸쳐 각 고객의 에너지 소비량과 요금을 공백으로 구분하여 출력합니다.
>>>코드
a, b = map(int, input().split())
for _ in range(int(input())):
n = int(input())
if n <= 1000:
print(n, a*n)
else:
print(n, a*1000 + b*(n-1000))