📄 2635368_ce.cpp
字号:
#include <iostream.h>
#include <math.h>
using namespace std;
int main()
{
int firsttime = 1;
int G, L;
while (cin >> G >> L)
{
if (!firsttime) cout << "\n";
firsttime = 0;
double exact = (double)G/L;
double bestapprox = floor(exact + 0.5);
cout << bestapprox << "/1\n";
for (unsigned i = 2; i <= L; ++i)
{
int estG = exact * i + 0.5;
double approx = (double)estG / i;
if (fabs(approx-exact) < fabs(bestapprox-exact))
{
bestapprox = approx;
cout << estG << "/" << i << "\n";
if (bestapprox == exact)
break;
}
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -