测试的都是对的但是WAqwq

P1303 A*B Problem

JayCRL @ 2024-01-13 17:00:56

#define _CRT_SECURE_NO_WARNINGS 1
#include <bits/stdc++.h>
using namespace std;
vector<int> c3;
void JW(int n,int i) {
    //那一位不存在
    if ((signed int)(c3.size()-1)<i) {
        if (n>=10){
            c3.push_back(n % 10);
            c3.push_back(n / 10);
        }
        else {
            c3.push_back(n);
        }
    }
    else {
        //那一位存在
        n = n + c3.at(i);
        if (n>=10) {
            c3.at(i) = n % 10;
            JW(n / 10,i+1);
        }
        else {
            c3.at(i) = n;
        }
    }
}
void PR() {
    reverse(c3.begin(), c3.end());
    vector<int>::iterator vv = c3.begin();
    while ((vv != c3.end())&& (*vv == 0)) {
        vv++;
    }
    if (vv==c3.end()) {
        printf("0");
    }
    else {
        for (vv; vv != c3.end(); vv++) {
            printf("%d", *vv);
        }
    }
}
void XC(vector<int>* G,vector<int>* D) {
    //倒叙遍历位数低的
    for (vector<int>::iterator c1 = D->begin(); c1 != D->end(); c1++) {
        //遍历高位的每一位
        for (vector<int>::iterator c2 = G->begin(); c2 != G->end(); c2++) {
            int number = (*c1) * (*c2);
            JW(number, (c1-(D->begin()))+(c2-(G->begin())));
        }
    }
}
int main() {
    vector<int> c1;
    vector<int> c2;
    char c;
    //读取第一个数存入容器
    while ((c = getchar()) != '\n' && c != EOF) {
        c1.push_back(c-'0');
    }
    //读取第二个数存入容器
    while ((c = getchar()) != '\n' && c != EOF) {
        c2.push_back(c-'0');
    }
    reverse(c1.begin(), c1.end());
    reverse(c2.begin(), c2.end());
    //判断哪个数更大
    c1.size() > c2.size() ? XC(&c1, &c2) : XC(&c2, &c1);
    PR();
}

为什么一个测试点过不了 自己测试的没问题


by jinyouchen1111111 @ 2024-08-05 20:05:17

#include<bits/stdc++.h>
using namespace std;
char a1[10000];
int a[10000],b[10000],c[10000],la,lb,lc;
int main(){
    cin>>a1;
    la=strlen(a1);
    for(int i=0;i<la;i++){
        a[la-i]=a1[i]-'0';
    }
    cin>>a1;
    lb=strlen(a1);
    for(int i=0;i<lb;i++){
        b[lb-i]=a1[i]-'0';
    }
    lc=la+lb+10;
    for(int i=1;i<=la;i++){
        for(int j=1;j<=lb;j++){
            c[i+j-1]+=a[i]*b[j];
            c[i+j]+=c[i+j-1]/10,c[i+j-1]%=10;
        }
    }
    while(!c[lc]&&lc>1)
        lc--;
    for(int i=lc;i;i--)
        cout<<c[i];
    return 0; 
} 

by jinyouchen1111111 @ 2024-08-05 20:05:26

@JayCRL


by jinyouchen1111111 @ 2024-08-05 20:13:02

dalao,本蒟蒻看不懂,俺还是个3年级的小人


|