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

CODE:

Posted by Judas at 2005-11-06 21:09:04 on Problem 2389
In Reply To:费解,读串WA,一个个的搞字符就AC了,以前也有道题是这样呢。请教! :> Posted by:Judas at 2005-11-06 20:42:05
#include<iostream>
using namespace std;
#define M 100
int c[M]={0};
void mul(char *a,char *b,int n,int m)
{
	memset(c,0,sizeof(c));
	int i,j,temp,t,tt;
	int num=0;
	for(i=0;i<m;i++)
	{
		for(j=0;j<n;j++)
		{
			temp=0;
			t=(a[n-1-j]-'0')*(b[m-1-i]-'0')+temp;
			if(0==t)	continue;//加上这句,前面冇0,WA
			num=j+i;		tt=c[num]+(t);	c[num]=tt%10;	
			if(temp=tt/10) { c[++num]+=temp; temp=0; }	
		}
	}
	for(i=num;i>=0;i--)	cout<<c[i];	//cout<<endl;	
}
int main()
{
	char a[41],b[41],ch,i,n,m;
	//cin>>a>>b; //这么读,也WA了 
	for(i=0;i<41;i++)  
	{
		scanf("%c",&ch);
		if(ch<'0'||ch>'9')      break;
		a[i]=ch;
	}
	n=i;
	for(i=0;i<41;i++)  
	{
		scanf("%c",&ch);
		if(ch<'0'||ch>'9')      break;
		b[i]=ch;
	}
	m=i;
	mul(a,b,n,m);		//strlen(a),strlen(b)
	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