competitive-programmingJan 21, 20211 min read

[BOJ] 15858. Simple Arighmetic Explained

Updated: Jan 21, 2021

Ad hoc
Available in:enko

#Problem

15858. Simple Arighmetic

#Approach

Computing with double gives 50 points. Computing with long double gives 75 points. Parsing the string and computing digit by digit yourself gives 100 points.

#Code

/**
 * 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;
}

#Complexity

  • Time: O(1)O(1)
  • Space: O(1)O(1)