Small algorithms: recursive retrieval judgment and recursive retrieval judgment

Source: Internet
Author: User

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 );
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.