hdu 1063

#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <vector>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
using namespace std;

const int N = 200;
const int INF = 0xfffffff;

//typedef long long ll;
typedef long double ld;

#define INFL 0x7fffffffffffffffLL
#define met(a, b) memset(a, b, sizeof(a))
#define rep(c, a, b) for (int c = a; c < b; c++)
#define nre(c, a, b) for (int c = a; c > b; c--)
//h(n ) = h(n-1)*(4*n-2) / (n+1)

int main ()
{
    int ans[N], r;
    string a;
    while (cin >> a >> r)
    {
        met (ans, 0);
        int k = 0, e = 0, xs = 0, x0 = 0;
        bool xss = false;
        for (int i=0; i<a.length(); i++)
        {
            if (a[i] != '.')
            {
                ans[k++] = a[i] - '0';
                e = e * 10 + (a[i] - '0');
            }
            else xss = true;
        }
        if(!r)
        {
            if (e == 0) cout << 0 << endl;
            else cout << 1 << endl;
            continue;
        }
        bool flag = false;
        if (xss)
        {
            for (int i=a.length()-1; i>=0; i--) //小数位数
            {
                if (a[i] == '.') break;
                if (a[i] != '0') flag = true;
                if (flag) xs++;
                else x0++;
            }
        }
        reverse (ans, ans + k);
        int c = 0;
        for (int i=1; i<r; i++)
        {
            for (int j=0; j<N; j++)
            {
                int x = ans[j] * e + c;
                ans[j] = x % 10;
                c = x / 10;
            }
        }
        int aa = 0, bb = N-1;
        if (xs) while (ans[aa] == 0) aa++;
        else if (x0) while (ans[aa] == 0 && x0) aa++, x0--;
        while (ans[bb] == 0) bb--;
        int tt = xs * r - bb + aa - 1;
        if (tt >= 0 && xs)
        {
            cout << ".";
            while (tt--) cout << 0;
        }
        for (int i=bb; i>=aa; i--)
        {
            cout << ans[i];
            if (i == aa +  xs * r && xs)
                cout << ".";
        }
        if (aa > bb) cout << 0;
        cout << endl;
    }
    return 0;
}

这道题写哭了 写到崩溃 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值