| ||||||||||
| 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 | |||||||||
测试了好多数据都正确,就是过不了~~~求大神帮忙看一下#include<stdio.h>
#include<memory.h>
#define MAX 500
int A[MAX];
char In[10];
char out[MAX];
int main()
{
int i,j,k,x=0,Out,flag = 0,count = 0,count0 = 0,dot;
int n,n1= 0,n2 = 0,num = 0,Total = 0;
while(scanf("%s %d",In,&n)!=EOF){
k = 5;
n1 = 0;
count0 = 0;
while(In[k]>57||(In[k]<48&&In[k]!='.')){
k--;
}
while(In[k] == '0'){
k--;
count0++;
}
if(In[k] == '.')
count0 = 0;
for(i = 0,k;k>=0;i++,k--){
if(In[k] == '.')//.46
{ //倒序,即A中存的数最低位在A[0]
n1=i;
k--;
}
if(k>=0)
A[i] = In[k]-48;
else
A[i] = 0;
}
n1 *= n; //n1为小数点后的位数
count0 *= n;
num = A[4];
num = num*10+A[3];
num = num*10+A[2];
num = num*10+A[1];
num = num*10+A[0]; //输入的浮点数去掉小数点后的结果
for(i = 1;i<n;i++){
for(j = 0;j<MAX;j++){
Out = A[j]*num+flag; //每一位同原数相乘,有进位的向上累计
flag = Out/10; //flag表示进位
A[j] = Out%10;
}
}
count = MAX-1;
while(A[count]==0){
count--;
}
count++;
dot = count-n1;
if(dot>=0){ //判断小数点位置
for(k = 0,j=count-1;j>=0;j--,k++){
if(j == (n1-1)&&n1!=0){
out[k++] = '.';
count++;
}
out[k] = A[j]+48;
}
if(n1 == 0&&count0>0){
for(j = 0;j<count0;j++){
out[k++] = 48;
count++;
}
}
}
else{
dot = 0-dot;
k = 0;
if(n1 != 0)
out[k]= '.';
for(j = count-1,k = 1;j>=0;k++){
if(dot == 0){
out[k] = A[j]+48;
count++;
j--;
}
else{
out[k] = 48;
dot--;
count++;
}
}
}
for(j = 0;j<MAX;j++){
if(n == 0){
printf("1");
break;
}
if(num == 0){
printf("0");
break;
}
printf("%c",out[j]);
out[j] = '\0';
}
memset(out,0,sizeof(out));
memset(A,0,sizeof(A));
memset(In,0,sizeof(In));
printf("\n");
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator