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

贡献出自己花了4天时间写的代码

Posted by laoyang103 at 2011-07-23 11:11:53 on Problem 1001
#include <stdio.h>
#include <string.h>
struct BigInt
{
	char bit[500];
	bool flag;
	int nbit;
};
void InPut(BigInt *p)
{
	if(p->bit[0] == '-')
		p->flag = 1;
	p->nbit = strlen(p->bit);
	int i,j,k;
	int len = p->nbit;
	i = 0;j = len-1;
	while(i<=j)
	{
		char temp = p->bit[i]-48;
		p->bit[i] = p->bit[j]-48;
		p->bit[j] = temp;
		i++;j--;
	}
	if(p->flag)
		p->bit[len-1] = 0;
	for(i = len-1;i>=0;i--)
		if(p->bit[i]>0 && p->bit[i]<=9)
			break;
	p->nbit = i+1;
}
void Multip(const BigInt a,const BigInt b,BigInt *res)
{
	if(a.flag == b.flag)
		res->flag = 0;
	int i = 0,j = 0,k = 0,low = 0;	
	while(i<b.nbit)
	{
		low = 0;
		while(j<a.nbit)
		{
			char num = low+a.bit[j]*b.bit[i];
			k = i+j;
			res->bit[k] += num%10;
			low = num/10;
			low += res->bit[k]/10;
			res->bit[k] %= 10;
			j++;
		}
		if(low)
			res->bit[i+j] += low;
		k = i+j;
		i++;j = 0;
	}
	if(low)
	    res->nbit = k+1;
	else
		res->nbit = k;
}
int main()
{
	BigInt b1 = {0},b2 = {0},b3 = {0};
	int n = 0;
	int i,j,k;
/*
	strcpy(b1.bit,"860709538625867");
	strcpy(b2.bit,"95123");
	InPut(&b1);
	InPut(&b2);
	Multip(b1,b2,&b3);
*/
	while(EOF != scanf("%s %d",b1.bit,&n))
	{
		j = 0;
		int pos = 0;
		if(n == 0)
		{
			printf("1\n");
			continue;
		}
		if(b1.bit[0] != '.')
		{

			for(i = 0;b1.bit[i];i++)
			{
		  		if(b1.bit[i] != '.')
				{
					b1.bit[j++] = b1.bit[i];
				}
				else
					pos = i;
			}		
			b1.bit[j] = '\0';
			if(pos)
				pos = strlen(b1.bit+pos);
			pos *= n;
		}
		else
		{
			pos = strlen(b1.bit+1);
			pos *= n;
			for(i = 0;b1.bit[i];i++)
			{
		  		if(b1.bit[i] != '.')
				{
					b1.bit[j++] = b1.bit[i];
				}
			}		
			b1.bit[j] = '\0';
		}
		InPut(&b1);
		b2 = b1;
		b3 = b2;
		while(n>1)
		{
			memset(&b3,0,sizeof(BigInt));
			Multip(b2,b1,&b3);
			b2 = b3;			
			n--;
		}
		i = b3.nbit-1>pos-1 ? b3.nbit-1:pos-1;
		for(j = 0;j<pos;j++)
			if(b3.bit[j])
				break;
		if(i<j)
		{
			printf("0\n");
			continue;
		}
		while(i>=j)
		{
			if(i+1 == pos)
				putchar('.');
		    putchar(b3.bit[i--]+48);
		}
		printf("\n");
	}
	return 0;
}

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