Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
晒晒我的代码 第1个ac的题目 高手给点意见哈#include<iostream> using namespace std; int mul(long int*,int,int); int out(long int*,int); int main() { long int temp[32]={0}; double R;int n;int xp; int r; while(cin>>R>>n) { xp=4; r=(int)(R*10000); while(r%10==0&&xp>0) {xp--;r/=10;} xp*=n; temp[0]=r%10000; temp[1]=r/10000; mul(temp,r,n); out(temp,xp); for(int i=0;i<32;i++) temp[i]=0; } return 0; } int mul(long int*temp,int multee,int n) { for(int j=0;j<n-1;j++) { for(int i=0;i<1.5*j+3.5;i++) temp[i]*=multee; for(int i=0;i<1.5*j+2.5;i++) temp[i+1]+=(temp[i]/10000); for(int i=0;i<1.5*j+3.5;i++) temp[i]%=10000; } return 0; } int out(long int*temp,int xp) { int i=xp/4;int j=31; int yu=xp%4; int last=0; cout.fill('0'); while(temp[j]==0&&j>i) j--; while(temp[last]==0&&last<i) last++; if(j==i) { if(yu==0)if(temp[j])cout<<temp[j]; if(yu==1)if(temp[j]/10)cout<<temp[j]/10; if(yu==2)if(temp[j]/100)cout<<temp[j]/100; if(yu==3)if(temp[j]/1000)cout<<temp[j]/1000; } else { cout<<temp[j]; for(j--;j>i;j--) {cout.width(4);cout<<temp[j];} if(yu==0){cout.width(4);cout<<temp[j];} if(yu==1){cout.width(3);cout<<temp[j]/10;} if(yu==2){cout.width(2);cout<<temp[j]/100;} if(yu==3)cout<<temp[j]/1000; } if(last==i) { if(yu==3) if(temp[j]%1000) { cout<<'.';cout<<temp[j]%1000/100; if(temp[j]%100) { cout<<temp[j]%100/10; if(temp[j]%10)cout<<temp[j]%10; } } if(yu==2) if(temp[j]%100) { cout<<'.';cout<<(temp[j]%100)/10; if(temp[j]%10)cout<<temp[j]%10; } if(yu==1) if(temp[j]%10) {cout<<'.';cout<<temp[j]%10;} } else { cout<<'.'; if(yu==1)cout<<temp[j]%10; if(yu==2){cout.width(2);cout<<temp[j]%100;} if(yu==3){cout.width(3);cout<<temp[j]%1000;} for(j=i-1;j>last;j--) {cout.width(4);cout<<temp[j];} if(temp[last]%10==0) if(temp[last]%100==0) if(temp[last]%1000==0) cout<<temp[last]%1000; else {cout.width(2);cout<<temp[last]%100;} else {cout.width(3);cout<<temp[last]%10;} else {cout.width(4);cout<<temp[last];} } cout<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator