zoukankan      html  css  js  c++  java
  • poj1001

    简单题

    先把小数点去掉(乘以10的若干次幂),按整数计算,然后再计算有多少小数位即可。

    View Code
    #include <iostream>
    #include <string>
    using namespace std;
    
    const int w = 100000, maxn = 300, ww = 5;
    
    string st, ansst;
    int pointpos, n, fac;
    long long ans[maxn];
    
    void init()
    {
        int i, x = 0;
    
        pointpos = 0;
        for (i = 0; i < 6; i++)
        {
            if (st[i] == '.')
            {
                pointpos = 6 - i - 1;
                continue;
            }
            x *= 10;
            x += st[i] - '0';
        }
        fac = x;
        cin >> n;
    }
    
    void mul(long long *ans, int fac)
    {
        int i;
        long long jw = 0, ls;
    
        for (i = 1; i <= ans[0]; i++)
        {
            ls = jw + ans[i] * fac;
            ans[i] = ls % w;
            jw = ls / w;
        }
        if (jw > 0)
        {
            ans[0]++;
            ans[ans[0]] = jw;
        }
    }
    
    void work()
    {
        int i;
    
        ans[0] = 1;
        ans[1] = 1;
        for (i = 0; i < n; i++)
            mul(ans, fac);
    }
    
    string tostring(long long x)
    {
        string re;
        int i, j;
    
        j = w;
        for (i = 0; i < ww; i++)
        {
            j /= 10;
            re += char('0' + x / j);
            x %= j;
        }
        return re;
    }
    
    void print()
    {
        int pp, i;
    
        ansst = "";
        for (i = ans[0]; i > 0; i--)
            ansst += tostring(ans[i]);
        while (ansst[0] == '0')
            ansst.erase(0, 1);
        pp = pointpos * n;
        if (pp > ansst.length())
            for (i = ansst.length(); i < pp; i++)
                ansst.insert(0, "0");
        if (pp > 0)
        {
            ansst.insert(ansst.length() - pp, ".");
            while (ansst[ansst.length() - 1] == '0')
                ansst.erase(ansst.length() - 1, 1);
        }
        if (ansst[ansst.length() - 1] == '.')
            ansst.erase(ansst.length() - 1, 1);
        cout << ansst << endl;
    }
    
    int main()
    {
        //freopen("t.txt", "r", stdin);
        while (cin >> st)
        {
            init();
            work();
            print();
        }
    }
  • 相关阅读:
    asp.net大文件断点续传
    JS大文件上传解决方案
    B/S大文件上传解决方案
    B/S上传整个文件夹
    网页上传整个文件夹
    POJ 1068 Parencodings
    74LS85 比較器 【数字电路】
    二叉树的建立与先序,后序,中序输出
    Android 学习之 开源项目PullToRefresh的使用
    理解矩阵及谱聚类小记
  • 原文地址:https://www.cnblogs.com/rainydays/p/2787571.html
Copyright © 2011-2022 走看看