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

Re:第一个高精度,嘿嘿

Posted by 696969 at 2010-03-15 09:18:46 on Problem 1503
In Reply To:第一个高精度,嘿嘿 Posted by:lijinwu at 2010-02-04 22:14:47
#include<stdio.h>
#include<string.h>
void main()
{
    void sum(char p[],char q[],char c[]);
    char a[100][100],c[100]={'0'};
	int i,j;
	for(i=0;i<100;i++)
	{
		scanf("%s",a[i]);
		if(a[i][0]=='0')
			break;
	}
	for(j=0;j<i-1;j++)
	{
        sum(a[j],a[j+1],c);
		strcpy(a[j+1],c);
	}
    puts(a[j]);
}
void sum(char p[],char q[],char c[])
{
    int i,j,k,m=strlen(p),n,l=strlen(q),x,t,a=0;
    for(i=0;i<m/2;i++)
    {t=p[i];p[i]=p[m-1-i];p[m-1-i]=t;}
    for(j=0;j<l/2;j++)
    {t=q[j];q[j]=q[l-1-j];q[l-1-j]=t;}
    if(m>l)
	{
        for(i=l;i<m;i++)
            q[i]='0';
		q[i]='\0';
	}
    else
	{
        for(i=m;i<l;i++)
            p[i]='0';
		p[i]='\0';
	}
    k=m;
    if(m<l)
        k=l;
    for(i=0;i<k;i++)
    {
        n=p[i]+q[i]-96+a;
        a=n/10;
        c[i]=n%10+48;
    }
    if(a==1)
        c[i]='1';
    x=strlen(c);
    for(i=0;i<x/2;i++)
    {t=c[i];c[i]=c[x-1-i];c[x-1-i]=t;}
}


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