Welcome

首页 / 软件开发 / 数据结构与算法 / 一个算法的实现

一个算法的实现2013-11-29某同学帮国外某MM做的题。

算法描述:

首先将两个字符串和一个临界值作为参数传入函数,比如"aaaaaaaaaa","bbaaababaa",2,然后在函数中依次比较两个字符串的每个字符,当不同的字符数超过指定的临界值后,继续比较,并将大于等于临界值且最大数目的第一个字符串中的相同字符转换为大写,比如,根据以上输入,那么输出为:aaAAAaaaAA。要求:只能用if,else,递归及字符串处理的相关函数。

欢迎各种拍砖。

//Code By Pnig0s1992//Date:2012,3,13#include <stdio.h>#include <Windows.h>#include <string.h>#include <stdlib.h> #define MAXSIZE 20 int SuperStr(CHAR lpFirst[],CHAR lpLast[],int iCheck); int main(int argc,char * argv[]){CHAR lpFirst[] = "aaaaaaaaaa";CHAR lpSecond[] = "bbaaababaa";int iCheck = 2;SuperStr(lpFirst,lpSecond,iCheck);printf("n修改后的第一条字符串:%s",lpFirst);system("pause");return 0;} 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;}
本文出自 “About:Blank H4cking” 博客,请务必保留此出处http://pnig0s1992.blog.51cto.com/393390/805284