※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 20374번 문제인 Big Money이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/20374 

 

20374번: Big Money

Every year, Paris welcomes dozens of millions of tourists, who bring a considerable revenue to the city and its tourist industry. As an employee of the tourism bureau of the city of Paris, you are tasked with computing how much money was spent by tourists

www.acmicpc.net

문자열로 주어지는 일정한 형태의 소수들을 모두 더한 값을 정확히 출력해주는 문제이다.

 

주어지는 소수에 100을 더해 얻을 수 있는 정수를 이용해 답을 계산하면 실수오차 걱정 없이 문제를 해결할 수 있다.

 

아래는 제출한 소스코드이다.

#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

ll ans;
string s;
ll X, Y;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	while (cin >> s) {
		int slen = s.length();
		ans += stoll(s.substr(0, slen - 3)) * 100 + stoll(s.substr(slen - 2, 2));
	}

	X = ans / 100, Y = ans % 100;
	cout << X << '.';
	if (Y < 10) cout << 0;
	cout << Y;
}
728x90

+ Recent posts