POJ_1001_Exponentiation_高精

来源:互联网 发布:阿里云dns解析设置 编辑:程序博客网 时间:2024/06/11 00:27

@%$&%!&*@$^*(!^%*&!^$@*&!$@^*&!@^$(&*$@(q&

POJ你……¥%#¥%#……&%&%!!!!!!!!

鉴于这道题给我带来的愉快经历,这次的生活感悟就多写点吧。

当初第一次见这道题吓尿我啊,这题排第二啊,然后TM劳资没学java要用高精度模拟我我擦类

本来模拟个整数就够烦,模拟小数乘法必然很不爽,

最重要的是,

POJ坑爹啊!!!

劳资从上午11点开始写,我刚用UBUNTU三天,完全不知道怎么调试啊,然后写了这么长的代码还没有自动纠错,于是就开始看着终端里面乱七八糟的编译结果开始找语法错误啊我擦!!!调试用了多长时间我都不记得了啊有木有,最后还是开win7用VS调出来了一个正常的数啊好不好,交上去还WA啊有木有!!!

WA到下午三点,然后看到评论区有一组神数据,于是到CSDN上找了个AC代码开始对拍,啪啪啪了好久啊有木有,发现尼玛不一样的数据坑爹啊有木有!!除了奇葩的前缀0和小数点开头,n>0你给了个n==0的数据是要闹哪样啊!!!非法啊有木有!!你不怕被警察叔叔抓走吗!!!

吐槽完了代码还是要改的,以防万一我把非法数据都给处理了,然后屁颠屁颠地交上去啊,

然后还是WA啊!!!

WA你妹啊,你是卖娃哈哈的吗!

然后又找各种数据对拍,零的零次方等于一这种数据都有人给啊。

然后交上去,还是WA啊!!

然后我手一抖,把语言从C++改成G++,就过了啊!!!

尼玛能不能告诉我这两个到底有什么区别啊,难道交题还要看运气吗!!!

我以后再也不选C++了!!!




题意:

给一个用六个字符表示的小数,以及一个整数,小数大于0.0小于99.999,整数大于0小于25

求小数的整数次方的精确值



Input

The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.

Output

The output will consist of one line for each line of input giving the exact value of R^n. Leading zeros should be suppressed in the output. Insignificant trailing zeros must not be printed. Don't print the decimal point if the result is an integer.

Sample Input

95.123 120.4321 205.1234 156.7592  998.999 101.0100 12

Sample Output

548815620517731830194541.899025343415715973535967221869852721.0000000514855464107695612199451127676715483848176020072635120383542976301346240143992025569.92857370126648804114665499331870370751166629547672049395302429448126.76412102161816443020690903717327667290429072743629540498.1075960194566517745610440100011.126825030131969720661201


这题就是模拟,但是代码长,像我这么水的人就很容易跪,当然用java的话都不是事。

明天得再把这份代码写几遍,免得下次高精又跪。


代码如下:

#include<iostream>#include<cstdio>#include<fstream>#include<cstring>#include<string>#include<cmath>using namespace std;#define mxl 510//ifstream fin("in.txt");//ofstream fout("out.txt");char zero[mxl];void set_zero(){memset(zero,0,sizeof(zero));zero[0]='0';}void cut_z(char in[]){int len=strlen(in);if(in[0]=='.'){char tem[mxl];memset(tem,0,sizeof(tem));tem[0]='0';for(int i=1;i<len+1;++i)tem[i]=in[i-1];++len;memset(in,0,sizeof(in));for(int i=0;i<len;++i)in[i]=tem[i];}bool ok=false;for(int i=0;i<len;++i)if(in[i]=='.'){ok=true;break;}if(ok){int loc=len-1;while(in[loc]=='0')in[loc--]=0;if(in[loc]=='.')in[loc]=0;len=strlen(in);}int loc=0;while(in[loc]=='0')++loc;if(in[loc]=='.'||loc==len)--loc;char tem[mxl];memset(tem,0,sizeof(tem));for(int i=0;i<len-loc;++i)tem[i]=in[i+loc];memset(in,0,sizeof(in));for(int i=0;i<len-loc;++i)in[i]=tem[i];}struct bign{int len,num[mxl];int dot;bign(){}bign(char in[]){cut_z(in);len=0;dot=-1;for(int i=strlen(in)-1;i>=0;--i){if(in[i]=='.'){dot=strlen(in)-i-1;continue;}num[len++]=in[i]-'0';}}bign multi(int x)const{bign ret;ret.len=len;if(x==10){ret.len=len+1;ret.num[0]=0;for(int i=1;i<ret.len;++i)ret.num[i]=num[i-1];return ret;}int pre=0;for(int i=0;i<len;++i){int tem=x*num[i]+pre;ret.num[i]=tem%10;pre=tem/10;}if(pre)ret.num[ret.len++]=pre;return ret;}bign& operator + (const bign& in)const{bign ret;ret.dot=-1;int pre=0;ret.len=max(len,in.len);for(int i=0;i<ret.len;++i){int tem;if(i>=len)tem=in.num[i]+pre;else if(i>=in.len)tem=num[i]+pre;elsetem=in.num[i]+num[i]+pre;pre=tem/10;ret.num[i]=tem%10;}if(pre)ret.num[ret.len++]=pre;return ret;}void cut_zero(){if(dot<0)return;int loc;bign tem;for(int i=0;i<len;++i){if(i==dot)break;if(num[i]){loc=i;break;}}tem.len=len-loc;for(int i=0;i<tem.len;++i)tem.num[i]=num[i+loc];tem.dot=dot-loc;*this=tem;}bign& operator * (const bign& in)const{bign ret(zero);int cnt=0;for(int i=0;i<len;++i){bign tem=in.multi(num[i]);for(int j=0;j<cnt;++j)tem=tem.multi(10);++cnt;ret=ret+tem;}ret.dot=in.dot+dot;ret.dot=max(ret.dot,-1);ret.cut_zero();return ret;}void print(){for(int i=len-1;i>=0;--i){if(dot!=-1&&dot==len-1&&i==len-1&&num[i]==0){//fout<<".";printf(".");continue;}//fout<<num[i];printf("%d",num[i]);if(i==dot)//fout<<".";printf(".");}//fout<<endl;puts("");}};int main(){set_zero();char a[10];int x;//while(fin>>a>>x){while(scanf("%s%d",a,&x)!=EOF){/*if(!x){//fout<<1<<endl;puts("1");continue;}*/bign fuck(a);/*if(!fuck.num[0]&&fuck.len==1){//fout<<0<<endl;puts("0");continue;}*/bign ans=fuck;for(int i=1;i<x;++i)ans=ans*fuck;ans.print();}return 0;}


0 0
原创粉丝点击