Implementation of an algorithm

Source: Internet
Author: User

A classmate to help some of the problems of MM.

Algorithm Description:

First, two strings and a critical value are passed as arguments to the function, such as "Aaaaaaaaaa", "Bbaaababaa", 2, and then in the function, each character of two strings is compared, and when the number of different characters exceeds the specified threshold, the comparison continues. and converts the same character in the first string that is greater than or equal to the critical value to uppercase, for example, depending on the input above, the output is: AAAAAAAAAA. Requirements: can only use If,else, recursion and string processing related functions.

Welcome to all kinds of brick-making.

//code by pnig0s1992//date:2012,3,13 #include <stdio.h> #include <Windows.h> #include <strin g.h> #include <stdlib.h> #define MAXSIZE int superstr (CHAR lpfirst[],char lplast[],int ICHEC  
     
k);  
    int main (int argc,char * argv[]) {char lpfirst[] = "AAAAAAAAAA";  
    CHAR lpsecond[] = "Bbaaababaa";  
    int icheck = 2;  
    Superstr (Lpfirst,lpsecond,icheck);  
    printf ("N modified first string:%s", Lpfirst);  
    System ("pause");  
return 0;  
    The int superstr (char lpfirst[],char lplast[],int icheck) {char Ctempf = *lpfirst;  
    CHAR Ctempl = *lplast;  
    int Itempmark;  
    Static CHAR Csave;  
    static LPSTR Lptempstr = (LPSTR) HeapAlloc (GetProcessHeap (), heap_zero_memory,20);  
    static int icount = 0;  
    int ireturn = 0;  
    if (Ctempf = = ' [] ' | | ctempl = = ' [] ') {return 0;  
          
    int isame = SUPERSTR (++lpfirst,++lplast,icheck);  
  if (Ctempf = = Ctempl)  {ctempf-=32;  
        Csave = Ctempf;  
        icount++;  
    Ireturn = 1;  
    }else {if (icount<icheck) icount = 0; } if (Icount >=icheck) {if (icount = 1) {Strnset (Lpfirst-1,ctempf,  
            icount);  
            icount = 0;  
        return 0;  
                }else {if (Isame = = 0) {strnset (lpfirst+1,csave,icount);  
            icount = 0;  
}} return Ireturn; }

This article is from the "About:blank h4cking" blog, please be sure to keep this source http://pnig0s1992.blog.51cto.com/393390/805284

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.