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

100道AC 纪念~!!!yeah!~ ~注意 n^0=1 0^n=0;

Posted by ecust_changzhu at 2009-07-20 17:22:19 on Problem 1001 and last updated at 2009-07-20 20:07:07



#include <stdio.h>
#include <string.h>
#define N 200
int main()
{
	int i,j,k,t;
	int p,q,temp1,temp2;
	int n,l,sign,count;
	char s[100];
	int a[N],sum[N],b[N];
	while(scanf("%s%d",s,&n)!=EOF)
	{
		memset(b,0,N*sizeof(int));
		memset(a,0,N*sizeof(int));
		l=strlen(s);
		b[0]=1;sign=0;
		for(i=l-1,j=0,count=0;i>=0;i--)
		{
			if(s[i]!='.') 
			{
				a[j]=s[i]-'0';
				count=count+a[j];
				j++;
			}
			else sign=j*n;
		}
		if(count==0) printf("0\n");
 		else if(n==0) printf("1\n");
		else 
		{
			for(i=1;i<=n;i++)
			{
				memset(sum,0,N*sizeof(int));
				for(j=0;j<N;j++)
				{
					t=j;
					for(k=0,temp1=0,temp2=0;k<N;k++)
					{
						temp1=sum[t]+a[j]*b[k]+temp2;
						sum[t]=temp1%10;
						temp2=temp1/10;
						t++;
					}
				}
				for(j=0;j<N;j++) b[j]=sum[j];
			}
			p=N-1;q=0; 
			while(sum[p]==0) p--;
			while(sum[q]==0&&q!=sign) q++;
			if(p+1>sign)
			{
				if(sign==q) 
				{
					for(i=p;i>=q;i--) printf("%d",sum[i]);
				}
				else
				{
					for(i=p;i>=q;i--)
					{
						if(i==sign&&sign!=0) printf("%d.",sum[i]);
						else printf("%d",sum[i]);
					}
				}
			}
			else 
			{
				printf(".");
				for(i=sign-1;i>=q;i--) printf("%d",sum[i]);
			} 
			printf("\n");
		}
	}
}




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