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;
    }
  • 相关阅读:
    Codis的源码编译生成tar包
    Jenkins安装war版本
    Eclipse中src/main/resources配置文件启动问题
    关于Web项目的pom文件处理
    spark streaming的理解和应用
    Azkaban安装
    Mysql安装
    Oracle递归操作
    WebService 入门
    BaseAction 类
  • 原文地址:https://www.cnblogs.com/NYNU-ACM/p/4236894.html
Copyright © 2011-2022 走看看