Problem


Key Idea

double로 계산하면 50점
long double로 계산하면 75점
문자열을 parsing해서 한 자리씩 계산하도록 직접 구현하면 100점

  • Time: \(O(1)\)


Implementation

/**
 * author: jooncco
 * written: 2021. 1. 21. Thu. 22:26:54 [UTC+9]
 **/

#include <bits/stdc++.h>
using namespace std;
typedef long long     ll;

ll a,b,c;

int main() {

    cin >> a >> b >> c;
    ll n= a*b;
    string ans= to_string(n/c);
    ans.push_back('.');
    for (int i=0; i < 20; ++i) {
        n %= c;
        n *= 10;
        if (n < c) ans.push_back('0');
        else       ans.push_back((char)('0'+n/c));
    }
    cout << ans;
}

Leave a comment