Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

不知道错在那里?大家拿去运行一下吧,谢谢!1

Posted by Aper at 2005-07-02 14:19:26 on Problem 1001
#include<stdio.h>
#include<string.h>
#define size 200

void init(char s[size]);
void cheng(char s[size],char r[6]);
void output(char s[size]);
int main()
{
    char r[6],s[size];
    int n,i;
    while(scanf("%s%d",r,&n)==2)
    {
        init(s);
        for(i=0;i<n;i++)
                cheng(s,r);
        output(s);
    }
    return 0;
}
void init(char s[size])
{
    int i;
    for(i=0;i<size;i++)
        s[i]='0';
    s[size-1]='1';
}

void cheng(char s[size],char r[6])
{
    char *pz;
    int p1,p2,p,i,j,k,b1,b2;
    char s0[size],r0[6];
    for(i=0;i<6;i++)
	r0[i]=r[i];
    pz=strstr(s,".");
    if (pz==NULL) p1=size-1;
    else p1=pz-s;
    pz=strstr(r0,".");
    if (pz==NULL) p2=5;
    else p2=pz-r0;
    p=size-1-p1+5-p2;
    for(i=0;i<size;i++)
	s[i]=s[i]-48;
    for(i=0;i<6;i++)
	r0[i]=r0[i]-48;
    i=size;
    while(s[i-1]<=0) i--;
    if(p1>=i) p=p-size+i+1;
    else p=p-size+i;
    if(p1<size-1)
    {
	for(j=p1;j>0;j--)
		s[j]=s[j-1];
	s[0]=0;
    }
    if(i<size)
    {
	if(p1>=i)
	{
		for(j=size-1;j>=size-i;j--)
			s[j]=s[j-size+i+1];
		for(j=0;j<size-i;j++)
			s[j]=0;
	}
	else
	{
		for(j=size-1;j>=size-i;j--)
			s[j]=s[j-size+i];
		for(j=0;j<size-i;j++)
			s[j]=0;
	}
    }
    i=6;
    while(r0[i-1]<=0) i--;
    if(i<=p2) p=p-6+i+1;
    else p=p-6+i;
    if(p2<5)
    {
	for(j=p2;j>0;j--)
		r0[j]=r0[j-1];
	r0[0]=0;
    }
    if(i<6)
    {
	if(p2>=i)
	{
		for(j=5;j>=6-i;j--)
			r0[j]=r0[j-6+i+1];
		for(j=0;j<6-i;j++)
			r0[j]=0;
	}
	else
	{
		for(j=5;j>=6-i;j--)
			r0[j]=r0[j-6+i];
		for(j=0;j<6-i;j++)
			r0[j]=0;
	}
    }
    b1=0;
    while(s[b1]==0) b1++;
    b2=0;
    while(r0[b2]==0) b2++;
    for(i=0;i<size;i++)
	s0[i]=0;
    for(i=5;i>=b2;i--)
	for(j=size-1;j>=b1;j--)
	{
		s0[j+i-5]+=r0[i]*s[j];
		s0[j+i-6]+=s0[j+i-5]/10;
		s0[j+i-5]=s0[j+i-5]%10;
	}
    for(i=size-1;i>0;i--)
    {
	s0[i-1]+=s0[i]/10;
	s0[i]=s0[i]%10;
    }
    if(p>0)
    {
	for(i=0;i<size-1-p;i++)
		s0[i]=s0[i+1];
	s0[size-1-p]='.'-48;
    }
    else if(p<0)
    {
	for(i=0;i<=size-1+p;i++)
		s0[i]=s0[i-p];
	for(i=size+p;i<size;i++)
		s0[i]=0;
    }
    for(i=0;i<size;i++)
	s[i]=s0[i]+48;
}

void output(char s[size])
{
    int b,e,p,i;
    char *pz;
    b=0;e=size-1;
    while(s[b]=='0') b++;
    pz=strstr(s,".");
    if (pz==NULL) p=size;
    else p=pz-s;
    if(p<size)
    {
        while(s[e]=='0') e--;
        if(s[e]=='.') e--;
    }
    for(i=b;i<=e;i++)
        printf("%c",s[i]);
    printf("\n");
}        

用TC++3.0及DEVC++试过了,也试了大家提供的BT数据,结果都没有错,但提交上去老是返回WrongAnswer,不知道是不是输出格式的问题。。。

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator