0分求救
  • 板块P1303 A*B Problem
  • 楼主Zeke
  • 当前回复7
  • 已保存回复7
  • 发布时间2021/11/19 11:47
  • 上次更新2023/11/4 00:10:01
查看原帖
0分求救
134088
Zeke楼主2021/11/19 11:47
//luogu P1303 A*B
#include <iostream>
using namespace std;

short a[3000]={0},b[3000]={0};
short c[5000000];

void swap(short &a,short &b)
{
    short c=a;
    a = b;
    b = c;
}

int main()
{
    char t;

    while(t = getchar())
    {
        if(t == '\n') break;
        a[++a[0]] = t-'0';
    }
    while(t = getchar())
    {
        if(t == '\n') break;
        b[++b[0]] = t-'0';
    }

    for(int i = 1;i <= (1+a[0])/2;i ++) swap(a[i],a[a[0]-i+1]);
    for(int i = 1;i <= (1+b[0])/2;i ++) swap(b[i],b[b[0]-i+1]);

    for(int i = 1;i <= a[0];i ++)
        for(int j = 1;j <= b[0];j ++)
        {
            c[i+j-1] += a[i]*b[j];
            if(i+j-1 > c[0]) c[0]=i+j-1;
        }

    for(int i = 1;i <= c[0];i ++)
    {
        if(c[i]/10)
        {
            c[i+1] += c[i]/10;
            c[i] %= 10;

            if(i == c[0]) c[0] ++;
        }
    }

    for(int i = c[0];i;i --) if(c[i] == 0) {c[0]--;break;}
    for(int i = c[0];i;i --) cout << c[i];cout << endl;

    return 0;
}

连第一个点都没过

测试数据下载了,输入输出都一样?

2021/11/19 11:47
加载中...