Algorithm improves recursive inverted character array time limit: 1.0s memory limit: 512.0MBThe problem description completes a recursive program, inverted character array. and print the implementation process
The recursive logic is:
When the character length equals 1 o'clock, return directly
Otherwise, replace the first two characters, in the recursive inverted character array of the remainder of the input format character array length and the array output format in the solution process, print character array changes.
The last empty line, at the end of the program, prints the elements of the array after it is inverted. Sample input
Sample ABCDE
Sample A
Sample output
Sample 1EBCDAEDCBAEDCBA
Sample 2a
Author notes: Compile to the result according to the topic is no problem, but the submission however, the egg hurts.
1#include <stdio.h>2 voidDaozhi (intBeginintEndChars[]) {3 if(Begin>=end)return;4 Else{5 Chartemp;6temp =S[begin];7S[begin] =S[end];8S[end] =temp;9printf"%s\n", s);TenDaozhi (begin+1, end-1, s); One } A - } - intMain () { the intLen; - Chars[10000]; -scanf"%d%s",&len,&s); -Daozhi (0, len-1, s); + for(intI=0; i<len;i++){ -printf"%c", S[i]); + } A return 0; at}
C language · Recursive inverted character array