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

数组开小了那么一点点就WA……呜呜呜

Posted by speedcell4 at 2011-02-05 23:36:20 on Problem 2389
这个AC了,但不知楼下的哥们说的直接用strlen有何影响

#include<stdio.h>
#include<string.h>
char a[44],b[44];
int c[200]={0};
int tell(char n)
{
    return n-'0';
}
void kan(int a,int b,int c[],int i)
{
    c[i]+=a*b;
    if(c[i]>9)
    {
        kan(1,c[i]/10,c,i+1);
        c[i]%=10;
    }
}
int main()
{
    gets(a);gets(b);int l1=strlen(a),l2=strlen(b),max=0;
    for(int i=l1-1;i+1;i--)
    {
        for(int j=l2-1;j+1;j--)
        {
            kan(tell(a[i]),tell(b[j]),c,l1+l2-2-i-j);
        }
    }
    for(int i=199;i+1;i--)
    {
        if(c[i]!=0)
        {
            max=i;
            break;
        }
    }
    for(int i=max;i+1;i--) printf("%d",c[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