영수증 (25304)

Created:

Baekjoon No.25304 문제
Baekjoon No.25304 예제
입력받은 금액에서 물건 가격을 모두 뺀 후에 남은 액수가 0이면 일치.

Bash

Bash
1
2
3
4
5
6
7
read t
read n
for ((i=0; i<n; i++)); do
	read p m
	((t -= p*m))
done
[ $t == 0 ] && echo "Yes" || echo "No"

C

C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>

int main(void) {
	int t, n, p, m;
	scanf("%d", &t);
	scanf("%d", &n);
	while (0 < n) {
		scanf("%d %d", &p, &m);
		t-=p*m;
		n--;
	}
	printf("%s\n", t == 0 ? "Yes" : "No");
	return 0;
}

Node.js

JavaScript
1
2
3
4
5
6
7
let [t, n, ...list] = require("fs").readFileSync(0).toString().trim().split("\n");
t*=1;
for (let l of list) {
	let [p, m] = l.split(" ").map(Number);
	t-=p*m;
}
console.log(t == 0 ? "Yes" : "No");

t*=1 == t = Number(t)

PHP

PHP
1
2
3
4
5
6
7
8
9
<?php
	fscanf(STDIN, "%d", $t);
	fscanf(STDIN, "%d", $n);
	for ($i=0; $i<$n; $i++) {
		fscanf(STDIN, "%d %d", $p, $m);
		$t -= $p * $m;
	}
	echo $t == 0 ? "Yes" : "No";
?>

Python3

Python
1
2
3
4
5
6
t = int(input())
n = int(input())
for i in range(n):
    p, m = map(int, input().split())
    t-=p*m
print("Yes" if t==0 else "No")

Ruby

Ruby
1
2
3
4
5
6
7
t = gets.chomp.to_i
n = gets.chomp.to_i
for i in 0...n
  p, m = gets.chomp.split().map {|i| i.to_i}
  t-=p*m
end
puts t == 0 ? "Yes" : "No"