求助www

P1255 数楼梯

Wen_SuHuai @ 2022-05-01 13:03:07

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed add(char a1[5010],char b1[5010]){
    int a[5010],b[5010],c[5010],lena,lenb,lenc,x;
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    lena = sizeof(a1);
    lenb = sizeof(b1);
    for(int i = 0 ; i < lena ; i++) a[lena - i] = a1[i] - 48; 
    for(int i = 0 ; i < lenb ; i++) b[lenb - i] = b1[i] - 48;
    lenc = 1;
    x = 0;
    while(lenc <= lena || lenc <= lenb){
        c[lenc] = a[lenc] + b[lenc] + x;
        x = c[lenc] / 10;
        c[lenc] %= 10;
        lenc++;
    }
    c[lenc] = x;
    if(c[lenc] == 0) lenc--;
    for(int i = lenc ; i > 0 ; i++) cout<<c[i];
}
signed slt(int N){
    cin>>N;
    if(N == 1) cout<<1;
    if(N == 2) cout<<2;
    string s1 = N + " ";
    else add(slt(s1-1),slt(s1-2));
} 
signed main(){
    slt();
    return 0;
} 

by Wen_SuHuai @ 2022-05-01 13:03:55

有哪里错的请dalao们指出来 蟹蟹了


by Fire_flame @ 2022-05-05 13:44:22

不能直接写 sizeof(a1)会编译错误。

你直接用循环找出最后一个数。


by Fire_flame @ 2022-05-05 13:45:15

还有slt函数里面的else与if之间不要加语句


by Fire_flame @ 2022-05-05 13:45:25

@Wen_SuHuai


by Wen_SuHuai @ 2022-05-14 13:01:10

蟹蟹啦 问题解决了


|