1026
时间限制: 1 Sec 内存限制: 512 MB
提交: 17 解决: 4
[ 提交][ 状态][ 讨论版]
题目描述
#include<iostream>
#include<string.h>
using namespace std;
char digui(char a[],int start,int end)
{
if(start>=end)
return 0;
else
{ char temp;
temp=a[start];
a[start]=a[end];
a[end]=temp;
puts(a);
digui(a,start+1,end-1);
}
}
int main()
{
int n,k,i;
string s;
while(cin>>s)
{
cin>>k>>n;
getchar();//吞掉空格
char a[1005];
gets(a);
cout<<s<<" "<<k<<endl;
digui(a,0,strlen(a)-1);
for(i=0;i<strlen(a);i++)
cout<<a[i];
cout<<endl;
}
}
完成一个递归程序,倒置字符数组。并打印实现过程
递归逻辑为:
当字符长度等于1时,直接返回
否则,调换首尾两个字符,在递归地倒置字符数组的剩下部分
输入
字符数组长度及该数组
输出
在求解过程中,打印字符数组的变化情况。
最后空一行,在程序结尾处打印倒置后该数组的各个元素。
最后空一行,在程序结尾处打印倒置后该数组的各个元素。
样例输入
Sample 15 abcdeSample 21 a
样例输出
Sample 1ebcdaedcbaedcbaSample 2a