| ||||||||||
| 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 | |||||||||
题号1001为什么vc6.0 和vc2010都编译通过了,OJ编译不通过。#include<stdio.h>
#include<string.h>
void cutstr(char * a)
{
int i,j;
i=strlen(a);
for(j=i-1;j>=0;j--)
{
if(a[j]!='0')
break;
a[j]=0;
i--;
}
}
void add(char * a,char * b,int wei)
{
int j,i,tmp;
for(j=0;a[j]!=0;j++)
{
for(i=0;i<=j+wei;i++)
if(b[i]==0)
b[i]='0';
i=j+wei;
for(tmp=a[j]+b[i]-2*'0'; tmp>0; tmp=tmp/10+b[++i] -'0')
{
if(b[i+1]==0 && tmp/10 !=0)
b[i+1]='0';
b[i] = tmp%10 +'0';
}
}
}
void multiply(char * a,char * b,char* c)
{
int i,j,strla,strlb;
char tmp[3];
strla= strlen(a);
strlb= strlen(b);
for(i=0;i<1000;i++)
c[i]=0;
for(j=0;j<strlb;j++)
for(i=0;i<strla;i++)
{
tmp[0] = (a[i]-'0')*(b[j]-'0')%10 + '0';
tmp[1] = (a[i]-'0')*(b[j]-'0')/10==0?0 : (a[i]-'0')*(b[j]-'0')/10 + '0';
tmp[2] = 0;
add(tmp,c,i+j);
}
}
int main(void)
{
char cs[1000],bcs[1000],r[7];
int i,j,n,dot;
while(scanf("%s %d",r,&n)==2)
{
for(i=0;i<1000;i++)
cs[i]=bcs[i]=0;
for(i=5,j=0;i>=0;i--)
{
if(r[i]=='.')
{
dot=5-i;
continue;
}
cs[j++]=r[i];
}
strcpy(r,cs);
for(i=0;i<n-1;i++)
{
multiply(cs,r,bcs);
strcpy(cs,bcs);
}
dot*=n;
cutstr(cs);
i=strlen(cs);
if(i>dot)
{
for(j=i;j>dot;j--)
cs[j]=cs[j-1];
cs[dot]='.';
}else
{
for(j=i;j<dot;j++)
cs[j]='0';
cs[dot]='.';
cs[dot+1]=0;
}
strrev(cs);
cutstr(cs);
printf("%s\n",cs);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator