10106 - Product
来源:互联网 发布:python输入ctrl c 编辑:程序博客网 时间:2024/06/17 13:28
TheProblem
The problem is to multiply two integers X, Y.(0<=X,Y<10250)
TheInput
The input will consist of a set of pairs of lines. Each line inpair contains one multiplyer.
TheOutput
For each input pair of lines the output line should consist oneinteger the product.
SampleInput
12122222222222222222222222222
SampleOutput
144444444444444444444444444
代码:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int len1,len2,z,ans[1001],ans1[1001];
void fun(char x[1001],char y[1001])
{
int i,j,k,c,bsum,t;
for(i=0;i<len2;i++)
{
memset(ans1,0,sizeof(ans1));
k=i;
c=bsum=0;
for(j=0;j<len1;j++)
{
bsum=c+(x[j]-'0')*(y[i]-'0');
ans1[j+k]=bsum;
c=bsum/10;
}
if(c>0)
ans1[j+k]=c;
c=bsum=0;
for(t=0;t<1001;t++)
{
bsum=ans[t]+ans1[t]+c;
ans[t]=bsum;
c=bsum/10;
}
}
}
int main()
{
int i,j;
char x[1001],y[1001],x1[1001],y1[1001];
while(scanf("%s%s",x,y)==2)
{
len1=strlen(x);
len2=strlen(y);
for(i=0,j=len1-1;i<len1;i++,j--)
x1[j]=x[i];
for(i=0,j=len2-1;i<len2;i++,j--)
y1[j]=y[i];
memset(ans,0,sizeof(ans));
if(len1>=len2)fun(x1,y1);
else
{
z=len1;
len1=len2;
len2=z;
fun(y1,x1);
}
for(i=1000;i>=0;i--)
if(ans[i]!=0)break;
if(i==-1)printf("0");
for(i;i>=0;i--)
printf("%d",ans[i]);
printf("\n");
}
return 0;
}
- 10106 - Product
- ios 修改xcode工程的product Name(…
-  
-
- hdoj acm 1008
- HDOJ 1984 Mispelling4
- em的错误 <转载>
- 集线器 交换机 路由器 网桥 …
- 死亡日志 ——黄妮超
- 使用BBED修改SCN …
- IOS 99乘法表
- 考 研 问 答
- hdoj acm 1029
- Rightmost Digit hdoj 1061
- HDOJ 1005 Number Sequence
- HDOJ 1722 Cake
- HDOJ 1350 Robot Motion
- HDOJ 1181 变形课
- uva 10361 - Automatic Poetry
- uva 401 - Palindromes
- uva UVa 537 Artificial Intellige…
- 409 Excuses, Excuses!
- 424 - Integer Inquiry
- 10106 - Product
- 465 - Overflow
- 安卓:内容提供者(基础知识)
- Problem A
- Problem B
- Problem F
- Problem G
- Problem C
- 1073(OnlineJudge)