Contest Duration: - (local time) (100 minutes) Back to Home

## A - kcal Editorial by en_translator

Since it is $$A/100$$ kilocalories per one milliliters, the answer is $$AB / 100$$. The following code (in C++) will be accepted:

#include <iostream>
using namespace std;

int main() {
int A, B;
cin >> A >> B;
cout << A * B / 100.0 << '\n';
return 0;
}


Here, if you express the operation of “dividing by 100” as A * B / 100, it will be rounded down since it is an integral operation. For example, 25 * 25 / 100 will be evaluated to 6, not 6.25. On the other hand, 100.0 is interpreted as a double type, so it will be processed as decimals.

One can explicitly cast to double type:

#include <iostream>
using namespace std;

int main() {
int A, B;
cin >> A >> B;
cout << ((double) (A * B)) / 100 << '\n';
return 0;
}


Note that although the code will be accepted under the constraints of the problem statement this time, if you feed $$A = 12345, B = 98765$$ as an input, it will output 1.21925e+07. Accurate notation can be obtained with std::fixed or std::setprecision.

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

int main() {
int A, B;
cin >> A >> B;
// std::fixed -> Instructs to output a fixed point decimal
// std::setprecision(int n) -> Instructs to output n digits after the decimal point
cout << fixed << setprecision(2);
cout << A * B / 100.0 << '\n';
return 0;
}


posted:
last update: