求查错

P1255 数楼梯

已注销&M73*K7U @ 2020-08-07 18:04:56

#include<bits/stdc++.h>
using namespace std;

string gj(string a12,string b12) {
    int a11[2000],b11[2000],sum11[2000],alen1,blen1,slen1;
    string c="";
    memset(a11,0,2000);
    memset(b11,0,2000);
    memset(sum11,0,2000);
    alen1=a12.size();
    for(int i=0; i<alen1; i++) a11[i]=a12[alen1-(i+1)]-48;
    blen1=b12.size();
    slen1=max(alen1,blen1);
    for(int i=0; i<blen1; i++) b11[i]=b12[blen1-(i+1)]-48;
    for(int i=0; i<slen1; i++) {
        sum11[i]+=(a11[i]+b11[i]);
        if(sum11[i]>=10) sum11[i+1]++,sum11[i]-=10;
    }
    if(sum11[slen1]>0) slen1++;
    slen1--;
    for(int i=slen1; i>=0; i--) {
        c+=char(sum11[i]+int('0'));
    }
    return c;
}

int n;
string a[5005];
int main() {
    scanf("%d",&n);
    if(n==0) {
        printf("0");
        return 0;
    }
    a[0]="1",a[1]="1";
    for(int i=2; i<=n; i++) {
        a[i]=gj(a[i-1],a[i-2]);
    }
    cout<<a[n];
    return 0;
}

2、10过不了

输入5000时返回乱码


by konjacp @ 2020-08-07 18:07:18

您数组就只开了2000,而且memset还写错了


by 已注销&M73*K7U @ 2020-08-07 18:08:50

2000就够了


by 已注销&M73*K7U @ 2020-08-07 18:09:24

@konjacp 我老师叫我这样写


by fresh_boy @ 2020-08-07 18:09:29

memset第三个参数是sizeo(数组名)


by konjacp @ 2020-08-07 18:10:31

@迷失在黑夜里 ?那您老师还真厉害


by 已注销&M73*K7U @ 2020-08-07 18:10:49

啊这,该怎么写


by zyk7 @ 2020-08-07 18:25:46

memset(all,0,sizeof(all);

by CornWorld @ 2020-08-24 09:01:05

@zyk7 少了个括号(((

memset(all,0,sizeof(all))

by zyk7 @ 2020-08-24 09:55:04

@Corn666 thx


by zyk7 @ 2020-08-24 09:55:50

不过您少打了分号


| 下一页