题意:输出n/23即可
解法一:
利用高精度的long double直接输出,但由于n的长度不确定,我们要加个限制%12Lf
#include <cstdio>
int main(){
long double x;
scanf ( "%15Lf", &x );//强制提高精度
printf ( "%.8Lf", x / 23 );//输出保留8位小数
return 0;
}
解法二:
先用字符串读取整个前18位的输入,然后再将字符串转化为12位的整数,除23,精度上没有任何损失,只是实现起来比较复杂而已
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
const int maxn=10000000+10;
char input[20];
ll poww(int n)
{
ll res=1;
for(int i=1;i<=n;i++)
res*=10;
return res;
}
int main()
{
ll ans=0;
for(int i=0;i<20;i++)input[i]='\0';
scanf("%18s",input);
if(input[0]=='1')ans=1e12;
else
{
for(int i=2;input[i]!='\0'&&i<=12;i++)
ans+=(input[i]-'0')*poww(13-i);
}
ans/=23;
ans/=1e3;
if(ans%10>=5)
printf("0.%08lld\n",ans/10+1);
else
printf("0.%08lld\n",ans/10);
return 0;
}
总结:想要高精度运算,1,使用long double 2 ,java 3,转换成整数运算