zoukankan      html  css  js  c++  java
  • 大数开方

    #include <iostream>
    using namespace std;
    #include <stdlib.h>
    #include <string.h>
    
    void sqrt(char *str)
    {
        double i,r,n;
        int j,l,size,num,x[1005];
        size=strlen(str);
        if (size==1&&str[0]=='0')
        {
            cout<<0<<endl;
            return;
        }
        if (size%2==1)
        {
            n=str[0]-48;
            l=-1;
        }
        else
        {
            n=(str[0]-48)*10+str[1]-48;
            l=0;
        }
        r=0,num=0;
        while (true)
        {
            i=0;
            while (i*(i+20*r)<=n)
                ++i;
            --i;
            n-=i*(i+20*r);
            r=r*10+i;
            x[num]=(int)i;
            ++num;
            l+=2;
            if (l>=size)
                break;
            n=n*100+(double)(str[l]-48)*10+(double)(str[l+1]-48);
        }
        for (j=0; j<num; ++j)
            cout<<x[j];
        cout<<endl;
        
    }
    int main()
    {
        char ch[1005];
        while (cin>>ch)
            sqrt(ch);
        return 0;
    }
  • 相关阅读:
    Android Studio相关
    iOS自动签名网站
    Ruby开发小记
    Python全栈之路目录结构
    不会docker的开发
    Centos7安装python3
    03 centos7的基本价绍
    02 centos虚拟机安装
    01 Linux虚拟机的安装
    跨域问题的解决
  • 原文地址:https://www.cnblogs.com/xiao-xue-di/p/9454261.html
Copyright © 2011-2022 走看看