zoukankan      html  css  js  c++  java
  • Problem E: Product

    Problem E: Product
    Time Limit: 1 Sec Memory Limit: 128 MB
    Submit: 18 Solved: 14
    [Submit][Status][Web Board]
    Description
    The problem is to multiply two integers X, Y. (0<=X,Y<10250)

    Input
    The input will consist of a set of pairs of lines. Each line in pair contains one multiplyer.

    Output
    For each input pair of lines the output line should consist one integer the product.

    Sample Input
    12
    12
    2
    222222222222222222222222
    Sample Output
    144
    444444444444444444444444
    my answer:

    #include<iostream>
    #include<cstring>
    #include<string>
    using namespace std;
    int main()
    {
     
        char a[100];
        char b[100];
        memset(a,'0',sizeof(a));
        memset(b,'0',sizeof(b));
        while(cin>>a>>b)
        {
            int sum[101]={0};
            int t1=strlen(a);
            int q=t1;
            int t2=strlen(b);
            for(int i=t2-1;t2>0,i>=0;i--){
                int p=100;
                for(int j=q-1,p=100+i-t2+1;j>=0;t1--){
                    sum[p--]+=((a[j--]-'0')*(b[i]-'0'));
                    }
            }
            for(int k=100;k>=0;k--){
                sum[k-1]+=sum[k]/10;
                sum[k]=sum[k]%10;
            }
            int start=0;
            while(!sum[start])
                start++;
            for(int j=start;j<=100;j++)
               cout<<sum[j];
            cout<<endl;
        }
        return 0;
    }
  • 相关阅读:
    链式前向星啊
    并 查 集 ! ! !
    看似很水的题--找画笔
    tarjan
    动态内存分配
    C++ 基础中的基础 ---- 引用
    STL 补档
    错题笔记和易错点提醒
    题解 P2253 【好一个一中腰鼓!】
    PAT-A1003
  • 原文地址:https://www.cnblogs.com/NYNU-ACM/p/4236894.html
Copyright © 2011-2022 走看看