| ||||||||||
| 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 | |||||||||
求助:提交总是wrong answer用sample input的数据测试,都是对的。
谁能提供一些测试数据?
谢谢
附源码:
#include "iostream"
#include <string.h>
#include "math.h"
const int N=125;
using namespace std;
void squeeze(char* p,int len,int fraction)
{
char * temp=p+(len-fraction-1);
for (int i=0;i<=fraction;i++)
*(temp+i) = *(temp+1+i);
}
void time(int * a1,int * a2)//a1=a1*a2,
{
int b[N]={0};
for(int i=N-1;i>=1;i--)
{
for(int j=N-1;j>=1;j--)
{
b[(i+j)-(N-1)]+=a2[i]*a1[j];
if (i+j>=N-1)
{
if (b[(i+j)-(N-1)]>=10)
{
b[(i+j)-(N-1)-1]+=b[(i+j)-(N-1)]/10;
b[(i+j)-(N-1)]=b[(i+j)-(N-1)]%10;
}
}
}
}
for(int i=0;i<N;i++)
a1[i]=b[i];
}
void power(int * a1,int n,int * result)//result=a1^n
{
if (n==1)
{
for(int i=0;i<N;i++)
result[i]=a1[i];
}
else
{
if(n%2==0)
{
power(a1,n/2,result);
time(result,result);
}
else
{
power(a1,(n-1)/2,result);
time(result,result);
time(result,a1);
}
}
}
int toInt(char ch)
{
if(ch>=0x30 && ch<=0x39)
return (int)ch-0x30;
}
int main(int argc, char * argv[])
{
char R[7];
int n,i,fraction=0;
int Rlen;
int exp;
char * p;
int * pa1;
int a1[N]={0},result[N]={0};
for(i=0;i<6;i++)
R[i] = '0';
// char result[N+1];
while(cin>>R>>n)
{
for(i=0;i<N;i++)
{
a1[i]=0;
result[i]=0;
}
Rlen=strlen(R);
p=strchr(R,'.');
if(p!=NULL)
{
fraction=Rlen-(p-R+1);
squeeze(R,Rlen,fraction);
Rlen=Rlen-1;
}
else
fraction=0;
fraction=fraction*n; //the number of fraction in result
for(i=0;i<Rlen;i++)
{
a1[N-1-i]=toInt(R[Rlen-1-i]);
result[N-1-i]=toInt(R[Rlen-1-i]);
}
power(a1,n,result);
i=0;
if(fraction>0)
{
int end = N-1;
while(result[end]==0)
end--;
while(*(result+i)==0 && i+fraction<N)
i++;
if(i+fraction==N)
{
cout<<'.';
while(i<=end)
{
cout<<*(result+i);
i++;
}
}
else
{
while(i<N-fraction)
{
cout<<*(result+i);
i++;
}
cout<<'.';
while(i<=end)
{
cout<<*(result+i);
i++;
}
}
}
else
{
while(*(result+i)==0)
i++;
while(i<N)
{
cout<<*(result+i);
i++;
}
}
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