手动测都对。。。交上去0分

P1303 A*B Problem

resftlmuttmotw @ 2018-11-09 18:12:04

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
using namespace std;
char a[2001],b[2001];
int c[100001];
int len;
bool flag;
void twosum(char a[],char b[])
{
    int i,lena=strlen(a);
    int j,lenb=strlen(b);
    for(i=lena-1;i>=0;i--)
    {
        int x1=a[i]-'0';
        for(j=lenb-1;j>=0;j--)
        {
            int x2=b[j]-'0';
            int location=lena-i+lenb-j-1;
            c[location]+=x2*x1;
            if(location>len) len=location;
        }
    }
    int carry=0;
    for(i=1;i<=len;i++)
    {
        int x=c[i]+carry;
        c[i]=x%10;
        carry=x/10;
    }
    if(carry>=1) c[++len]=carry;
}
int main()
{
    gets(a),gets(b);
    twosum(a,b);
    bool f=1;
    for(int i=len;i>=1;i--)
    {
        if(c[i]==0&&f&&i>1) continue;
        f=0;
        printf("%d",c[i]);  
    }
    return 0;
}

by 小粉兔 @ 2018-11-09 18:14:36

gets是时代的眼泪,还在用?


by UKE自动稽 @ 2018-11-09 18:17:11

@resftlmuttmotw 别用gets,那玩意儿被C++11废了


by resftlmuttmotw @ 2018-11-09 18:19:42

把gets改成scanfAC了。。。。


by kma_093 @ 2018-11-09 19:14:45

关于gets:他死了


|