Small algorithms: recursive retrieval judgment and recursive retrieval judgment
Static void Main (string [] args) {DateTime dt1 = DateTime. now; string text = "abcdedcba"; bool bYes = Recv (text); Console. write ("{0 }:{ 1} reply! ", Text, bYes? "Yes": "not"); DateTime dt2 = DateTime. now; Console. write ("Time consumed: {0} millisecond", (dt2-dt1 ). totalMilliseconds. toString (); Console. readLine ();} private static bool Recv (string text) {string head = text. substring (0, 1); string end = text. substring (text. length-1, 1); if (head = end) {if (text. length = 1) return true; string t = text. substring (1, text. length-2); return Recv (t);} return false ;}
Recursive Determination of input strings
# Include <iostream. h>
# Include <string. h>
Int huiwen (char s [], int len, int I)
{
If (I> (len-1)/2)
{
If (s [I] = s [len-1-i])
Return 1;
Else
Return 0;
}
Else
{
If (s [I] = s [len-1-i])
Return huiwen (s, len, I + 1); // recursion is performed if the return condition is met.
Else
Return 0;
}
}
Int main ()
{
Char s [20];
Int len;
Cin> s;
Len = strlen (s );
Cout }
C language uses recursion to determine whether a number is a return number
First, obtain the length n of the number,
Then, judge whether the second and NTH digits are equal.
Whether the I-th and n + 1-i-Th are equal. I loop
Write a function to obtain the I-bit size of this number.
Int GetI (int I, int number ){
If (I = 1)
Return number % 10;
Return GetI (I-1, number/10 );
}