acm poj1001 编译通过网上能找到的数据都试了一直没问题但一提交就wrong answer

#include
using namespace std;
int main()
{
char *MMO(char *many,char one,int offset);
void MPM(char *m1,char *m2);
char *MMM(char *m3,char *m4);
char *RN(char *R,int N);
char *outformal(char *r);
char *outlater(char res[]);
void output(char *r,int count,int N,int h);
char R[10];
int N,i,j,M;
char *r;
while(cin>>R>>N)
{
int count=-1;
int h=strlen(R);
for(i=j=0;i {
if(R[i]!='.')
{
R[j++]=R[i];
}
if(R[i]=='.')
count=i;
}
R[j]='\0';
M=atoi(R);
if(N==0)
cout else if(M==0)
cout else
{
r=RN(R,N);
output(r,count,N,h);
}
}
return 0;
}
char *MMO(char *many,char one,int offset)
{
int n1,n2,ses,i,mLength;
char *r;
int carry=0;
n1=one-48;
mLength=strlen(many);
r=new char[mLength+1+offset+1];
for(i=0;i r[i]='0';
r[mLength+1+offset]='\0';
for(i=mLength-1;i>=0;i--)
{
n2=many[i]-48;
ses=n1*n2;
ses=ses+carry;
r[i+1]=ses%10+48;
carry=ses/10;
}
r[0]=carry+48;
return r;
}
void MPM(char *m1,char *m2)
{

int n1,n2;
int carry=0;
int L1=strlen(m1);
int L2=strlen(m2);
for(int i=1;i<=L1;i++)
{
n1=m1[L1-i]-48;
if(L2-i<0)
n2=0;
else
n2=m2[L2-i]-48;
m1[L1-i]=(n1+n2+carry)%10+48;
carry=(n1+n2+carry)/10;
}
if(L1!=L2)
m1[L1-L2-1]=carry+48;
delete m2;
}
char *MMM(char *m3,char *m4)
{
char *e;
int i;
int L1=strlen(m3);
int L2=strlen(m4);
e=new char[L1+L2+1];
for(i=0;i<L1+L2;i++)
e[i]='0';
e[L1+L2]='\0';
if(L1<L2)
{
char *tap=m4;
m4=m3;
m3=tap;
int rag=L2;
L2=L1;
L1=rag;
}
for(i=0;i<L2;i++)
{
char *reg=MMO(m3,m4[L2-i-1],i);
MPM(e,reg);
}
return e;
}
char *RN(char *R,int N)
{
if(N<2)
return R;
char *res=MMM(R,R);
for(int i=0;i<N-2;i++)
{
char * res2 = res;
res = MMM(res, R);
delete res2;
}
return res;
}
char *outformal(char *r)
{
int num,i,j;
char res[1000];
i=0;
if(r[0]=='0')
{
while(r[i]=='0')
{
num=i;
i++;
}
for(j=0;r[num]!='\0';num++)
{
res[j++]=r[num+1];
}
res[j]='\0';
r=res;
return r;
}
else
return r;
}
char *outlater(char res[])
{
int num1=0;
int n=strlen(res)-1;
for(n;res[n]=='0';n--)
{
res[n]='\0';
}
int m=strlen(res)-1;
if(res[m]=='.')
res[m]='\0';
return res;
}
void output(char *r,int count,int N,int h)
{
int n=strlen(r);
int i,j;
char result[1000];
if(count<0)
{
char *res=outformal(r);
cout<<res<<endl;
}
else
{
j=0;
if((n-(h-1-count)*N-1)<0)
{

result[j]='.';
j++;
}
for(i=0;r[i]!='\0';i++)
{
result[j]=r[i];
j++;
if(i==(n-(h-1-count)*N-1))
{
result[j]='.';
j++;
}
}
result[n+1]='\0';
char *answer=outlater(result);
char *res=outformal(answer);
cout<<res<<endl;
}
}

1个回答

这道题还是用java做吧。。。。

import java.util.*;  
import java.math.*;  

public class Main {  

    public static void main(String[] args) {  
        // TODO Auto-generated method stub  
        Scanner input=new Scanner(System.in);  
        while(input.hasNext()){  
            BigDecimal a=input.nextBigDecimal();  //大数类的double;  
            int b=input.nextInt();  
            a=a.pow(b);  
            String ans=a.stripTrailingZeros().toPlainString();  //去掉尾部零,转换成非科学计数法字符串    
            if(ans.charAt(0)=='0'){  //如果以0开头    
                ans=ans.substring(1);  //返回以位置1开头的该字符串    
            }  
            System.out.println(ans);  

        }  

    }  

}  

WYHYDHD
WYHYDHD 可是一直想搞明白自己这个代码哪里错了
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问