Brian Warehouse

Some birds aren`t meant to be caged, their feathers are just too bright... ...
posts - 40, comments - 16, trackbacks - 0, articles - 1

大数问题学习周(2):POJ Grids 2980 大整数乘法

Posted on 2010-08-17 14:24 Brian 阅读(407) 评论(0)  编辑 收藏 引用 所属分类: POJ
#include <iostream>
#include 
<string>
using namespace std;

int main()
{
    
int a[200],b[200],c[400]={0},i,j,ls1,ls2;
    
string s;
    
    
for (cin>>s,ls1=s.length(),i=ls1-1,j=0; i>=0; i--)
        a[j
++]=s[i]-'0'//将第一个数逆序放入a数组
    
    
for (cin>>s,ls2=s.length(),i=ls2-1,j=0; i>=0; i--)
        b[j
++]=s[i]-'0'//将第二个数逆序放入b数组

    
for (i=0; i<ls1; i++)
        
for (j=0; j<ls2; j++)
        {
            c[i
+j] += a[i]*b[j];
            
if(c[i+j] >= 10)
            {
                c[i
+j+1+= c[i+j]/10;
                c[i
+j] %= 10;
            }
        }
    
    i
=399;
    
while (i--)
        
if (c[i]) break//跳过所有前导0
    for (; i>=0; i--)
        printf(
"%d",c[i]); //输出主体部分
    return 0;
}

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理