![[백준 / BOJ] 25304번 영수증 (C++, Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FckMzyo%2FbtrMaeqJqDA%2FBc3IaXImGDWKc9zfWbFDQk%2Fimg.jpg)
[백준 / BOJ] 25304번 영수증 (C++, Python)◎ 자료구조와 알고리즘/백준(BOJ) 문제풀이2022. 9. 14. 20:39
반응형
링크 : https://www.acmicpc.net/problem/25304
25304번: 영수증
준원이는 저번 주에 살면서 처음으로 코스트코를 가 봤다. 정말 멋졌다. 그런데, 몇 개 담지도 않았는데 수상하게 높은 금액이 나오는 것이다! 준원이는 영수증을 보면서 정확하게 계산된 것
www.acmicpc.net
문제

문제 풀이
차근차근 문제에서 주어진 대로 따라가면 된다. 삼항 연산자도 섞어보았다.
코드 전문
C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
void init() { | |
std::ios_base::sync_with_stdio(false); | |
std::cin.tie(nullptr); | |
std::cout.tie(nullptr); | |
} | |
int main() { | |
init(); | |
int X, N, a, b, res = 0; | |
std::cin >> X >> N; | |
for (int i = 0; i < N; ++i) { | |
std::cin >> a >> b; | |
res += a * b; | |
} | |
std::cout << ((X == res) ? "Yes" : "No"); | |
return 0; | |
} |
Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
input = sys.stdin.readline | |
if __name__ == "__main__": | |
res = 0 | |
X = int(input()) | |
for i in range(int(input())): | |
a, b = map(int, input().split()) | |
res += a * b | |
print("Yes") if X == res else print("No") |
소감
반응형
'◎ 자료구조와 알고리즘 > 백준(BOJ) 문제풀이' 카테고리의 다른 글
[백준 / BOJ] 10998번 팰린드롬인지 확인하기 (Python) (0) | 2024.03.13 |
---|---|
[백준 / BOJ] 2444번 별 찍기 - 7 (Python) (0) | 2024.03.12 |
[백준 / BOJ] 2480번 주사위 세개 (C++, Python) (0) | 2022.09.13 |
[백준 / BOJ] 2525번 오븐 시계 (C++, Python) (0) | 2022.09.13 |
[백준 / BOJ] 1330번 두 수 비교하기 (C++, Python) (부제 : 삼항 연산자) (0) | 2022.09.05 |
@Reo :: 코드 아카이브
자기계발 블로그