| ||||||||||
| 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还是1001~~~为什么我老是WA呢?请帮我看看~~~`THX#include<iostream>
using namespace std;
#define MAX_LEN 256
//a:乘数1 0位保存整数位数
//c:保存积
inline void mul( int c[],int a[], int b[])
{
int i,j,k,l;
int lena,lenb;
lena = a[0] + 1;
lenb = b[0] + 1;
for(i=1;i <= lenb;i++)
{
k=i;
for(j=1;j <= lena;j++)
{
c[k] = c[k]+a[j]*b[i];
l = k;
while(c[l]>=10)
{
c[l+1] += (c[l]/10);
c[l] %= 10;
l++;
}
k++;
}
}
c[0] = l - 1; // len
}
int main()
{
int n;
int i,j,k;
int ppos; //point's position
int len; //float len
char s[64];
int strNum[ MAX_LEN ]; // work array
int strInt[MAX_LEN];
int Tmp[MAX_LEN];
while(cin>>s>>n)
{
ppos = 0;
memset(strNum,0,MAX_LEN*sizeof(int));
memset(strInt,0,MAX_LEN*sizeof(int));
strNum[0] = len = strlen( s ) - 1; // charaters and .', so minus 2
//find point
for( i = 0; i< len; i++)
{
if( s[i] != '.' )
{
ppos++;
}
else
break;
}
//input range check
if( n > 25 || n < 0 )
continue;
if( n == 0 )
{
cout<<1<<endl;
continue;
}
//change to array
j=1;
for( i=len; i >= 0; i-- )
{
if( s[i] != '.' )
strInt[j++] = s[i] - '0' ;
}
j--;
strInt[0] = j;
i = 1;
for( ;i < j && strInt[i]==0 ;i++ );
if( i != 1 )
{
for( k = 1 ; i <= j ; k++,i++)
{
strInt[ k ] = strInt[ i];
strInt[ i] = 0;
}
len = strInt[0] = k - 1;
}
//0.0
if( len == 1 && strInt[1] == 0 )
{
cout<<0<<endl;
continue;
}
//calc
mul( strNum, strInt, strInt);
for( i = 1; i < n - 1; i++ )
{
//copy strInt to strIntTmp
memset(Tmp,0,MAX_LEN*sizeof(int));
for(j=0;j <= (strNum[0]+1) ;j++)
Tmp[j] = strNum[j];
memset(strNum,0,MAX_LEN*sizeof(int));
mul( strNum,Tmp, strInt);
}
//insert point
j = (len - ppos)*n;
for( i = strNum[0]; strNum[i]==0 && i>j; i--);
for( ; i>j; i--)
cout<<(char)(strNum[i] + '0');
if( i != 0 )
cout<<'.';
for( j=1; strNum[j]==0 && j < i; j++);
for(;i>j-1;i--)
cout<<(char)(strNum[i] + '0');
cout<<endl;
//initilize
memset(s,0,8);
}
return 0;
}
-----------
测试页上数据都OK
连论坛上看到的
0.0 3
1.000 3
12 0
...
等都通过了,但是就是WA~~~~究竟还要什么测试数据呢?
(我看了其他代码AC的但是有数据也通不过呀~~~为什么~~~~~:(
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator