关于递归做本题(求助)
查看原帖
关于递归做本题(求助)
367427
4ao_3ean楼主2020/11/21 20:05

RT

蒟蒻一枚,刚学递归,想用递归

输入:3 65 23 5 34 1 30 0

输出:30 1 34 5 23 65 3 3

会多一个3

不知道错哪了

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int MAXN=20001;
int arr[MAXN]; 
void Rcrs(int arr[],int length){
	if(length==0)	cout<<arr[0];
	else{
		cout<<arr[length-1]<<" ";
		Rcrs(arr,length-1);
	}
}
int main(){
    ios::sync_with_stdio(false);
    int length=0; 
    int tmp;
    for(int i=0;;i++)
    {
    	cin>>tmp;
    	if(tmp!=0)	arr[i]=tmp;
		else if(tmp==0){ length=i; break; } 
	}
	Rcrs(arr,length);	
	return 0;
}

2020/11/21 20:05
加载中...