Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- pair<int, string> parseLine(const string &line) {
- int nr = 0, i;
- for (i = 0; line[i] != ' '; i++) {
- nr = 10 * nr + line[i] - '0';
- }
- return make_pair(nr, line.substr(i + 1));
- }
- void solve(const vector<string> &lines) {
- double ans = 0;
- for (const auto &line : lines) {
- const auto &[nr, unity] = parseLine(line);
- if (unity == "kg") {
- ans += nr * 1e3;
- } else if (unity == "mg") {
- ans += 1.0 * nr / 1e3;
- } else {
- ans += nr;
- }
- }
- cout << fixed << showpoint << setprecision(5) << ans << " g" << endl;
- }
- vector<string> read() {
- vector<string> lines;
- for (string line; getline(cin, line);) {
- lines.push_back(line);
- }
- return lines;
- }
- signed main() {
- freopen("text.in", "r", stdin);
- solve(read());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement