90tps 最后一个RE

P1255 数楼梯

yinzixia @ 2024-08-12 10:00:46

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

int a[1005]={1},b[1005]={1},c[1005]={3},len=1;
void f(){
    int x=0;
    for(int i=0;i<len;i++){
        c[i]=a[i]+b[i]+x;
        x=c[i]/10;
        c[i]%=10;
    }
    if(x!=0){
        c[len]=x;
        len++;
    }
    for(int i=0;i<=len;i++){
        a[i]=b[i];
        b[i]=c[i];
    }
}
int main(){
    int n;
    cin>>n;
    n++;
    for(int i=3;i<=n;i++)f();
    for(int i=len-1;i>=0;i--)cout<<b[i];
    return 0;
}

by simple_child @ 2024-08-12 10:02:37

@yinzixia 数组不能这样初始化吧


by dyyzy @ 2024-08-12 10:02:42

@yinzixia 数组开小了


by yinzixia @ 2024-08-12 10:04:53

@simple_child @dyyzy 谢谢


by dyyzy @ 2024-08-12 10:05:17

@simple_child 为什么不可以


by simple_child @ 2024-08-12 10:06:44

@dyyzy c[1005]={3}这个合法吗,我老师说不行


by yinzixia @ 2024-08-12 10:07:09

@dyyzy AC了,谢谢


by dyyzy @ 2024-08-12 10:08:53

@simple_child 显然是合法的, 3 \to c[0] 其余均为 0


by simple_child @ 2024-08-12 10:11:46

@dyyzy 懂了谢谢


|