P2393 yyy loves Maths II

P2393 yyy loves Maths II
long double
比如保留5位小数
*1000000都变成整数
最后再/1000000避免精度误差
scanf("%Lf",&x);
printf("%.Lf",x);

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstring>
#define inf 2147483647
#define For(i,a,b) for(register int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar()
//by war
//2017.10.21
using namespace std;
long double sum,x,t=1000000;

void in(int &x)
{
    int y=1;
    char c=g();x=0;
    while(c<'0'||c>'9')
    {
    if(c=='-')
    y=-1;
    c=g();
    }
    while(c<='9'&&c>='0')x=x*10+c-'0',c=g();
    x*=y;
}
void o(int x)
{
    if(x<0)
    {
        p('-');
        x=-x;
    }
    if(x>9)o(x/10);
    p(x%10+'0');
}
int main()
{
//    freopen("t.in","r",stdin);
//    freopen("t.out","w",stdout);
    while(scanf("%LF",&x)!=EOF)
    sum+=x*t;
    printf("%.5LF",sum/t);
     return 0;
}

 

posted @ 2017-10-21 08:30  WeiAR  阅读(255)  评论(0编辑  收藏  举报