Coding/Step By Step

Baekjoon Training / 반복문 / #25304

빈그레 2023. 2. 18. 22:53

 

 


#25304

 

 

 

 

 

#include <iostream>
#include <vector>
using namespace std;

int main() {
	//총금액
	int given_total;
	cin >> given_total;

	//물건 종류 개수
	int item_count;
	cin >> item_count;

	//계산에 필요한 인자
	int calculated_total = 0;
	int each_price=0;
	int each_count=0;


	for (int i = 0;i < item_count;i++) {
		cin >> each_price >> each_count;
		calculated_total += each_price * each_count;
	}

	if (given_total == calculated_total) {
		cout << "Yes";
	}
	else cout << "No";

}

 

처음엔 벡터를 사용하여 모든 데이터를 저장하려 했으나,

데이터는 그 곱을 총 계산 가격에 더한 이후에는 필요가 없으므로 동일한 변수를 반복하여 재사용하였다.