每日刷题(五十七)
ALGO-246、猴子吃包子
这个题用C++做的话就会非常简单,我强烈建议如果要考蓝桥的同学如果C++不会,那从现在开始赶紧学,趁一切还来得及,C++里面有很多不错的函数,如果要自学我推荐C++ Primer Plus
详细C++代码如下:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int x, y, z, p;
double x1, y1, z1;
scanf("%d %d %d", &x, &y, &z);
scanf("%lf %lf %lf %d", &x1, &y1, &z1, &p);
int const a = p;
int i;
long long cnt = 1;
for(i = 0; i < p; i++)
{
cnt *= 10;
}
x1 = x1 * cnt / x;
y1 = y1 * cnt / y;
z1 = z1 * cnt / z;
cout << fixed << setprecision(a) << (x1 + y1 + z1) / cnt;
return 0;
}
样例运行结果如下: