美文网首页
2020-07-21 A*B Problem

2020-07-21 A*B Problem

作者: JalorOo | 来源:发表于2020-07-21 22:34 被阅读0次

https://www.luogu.com.cn/problem/P1303

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;

int read(){
    int x = 0,f = 1;
    char c = getchar();
    while (c<'0'||c>'9') {
        if (c=='-') {
            f = -1;
        }
        c = getchar();
    }
    while (c>='0'&&c<='9') {
        x = x*10+c-'0';
        c = getchar();
    }
    return x*f;
}

int a[2005],b[2005],c[10001];

int main ()
{
    string a1,b1;
    cin>>a1>>b1;
    
    int lena = a1.length();//字符串长度
    int lenb = b1.length();//字符串长度
    
    for(int i=1;i<=lena;i++){
        a[i]=a1[lena-i]-'0';
    }
    
    for(int i=1;i<=lenb;i++){
        b[i]=b1[lenb-i]-'0';
    }
    
    for(int i=1;i<=lenb;i++){
        for(int j=1;j<=lena;j++){
            c[i+j-1]+=a[j]*b[i];
        }
    }
    
    for(int i=1;i<lena+lenb;i++){
        if(c[i]>9){
            c[i+1]+=c[i]/10;
            c[i]%=10;
        }
    }
    
    int len=lena+lenb;
    
    while(c[len]==0&&len>1){
        len--;
    }
    
    for(int i=len;i>=1;i--){
        cout<<c[i];
    }
    
    return 0;
}
/*
1000000000000000000000
199
 
 46546876443156448001
 46453168410002134684
 93000044853158582685
*/

相关文章

  • 2020-07-21 A*B Problem

    https://www.luogu.com.cn/problem/P1303

  • ACM(eight)

    A + B Problem Too This problem is also a A + B problem,bu...

  • HDU 2101 A + B Problem Too

    Problem Description This problem is also a A + B problem,...

  • A + B Problem

    Description:Input and output are the same with problem 10...

  • A + B Problem

    输入多组数据,将输入作为判断的条件。 定义两个整型变量作为A,B,然后进行数学计算,输出两者之和。 https:/...

  • A + B Problem

    InputEach line will contain two integers A and B. Process...

  • A+B Problem too

    This problem is also a A + B problem,but it has a little ...

  • A + B Problem Too

    This problem is also a A + B problem,but it has a little ...

  • 8

    This problem is also a A + B problem,but it has a little ...

  • HDU - 2101 #A + B Problem Too

    This problem is also a A + B problem,but it has a little ...

网友评论

      本文标题:2020-07-21 A*B Problem

      本文链接:https://www.haomeiwen.com/subject/ehjgkktx.html