蓝桥杯 小数第n位

50 阅读1分钟

0小数第n位 - 蓝桥云课 (lanqiao.cn)

刚开始是模拟做的,能过样例但是过不了数据:

#include<bits/stdc++.h>
using namespace std;
#define int long long
int k = 3;
signed main()
{
	int a, b, n; cin >> a >> b >> n;

	double temp = a * 1.0 / b;

	string str = to_string(temp);

	for (int i = 0; i < str.size(); i++)
	{
		if (str[i] == '.')
		{int j = i + n;
			while (k--)
			{
				cout << str[j];
				j++;
			}
		}
	}

	return 0;
}

image.png image.png