• 模式匹配算法Index


    返回子串T在主串S中第pos个字符之后的位置。若不存在,则函数返回值为0。
    T非空,1<=pos<=StrLength(S)

    int Index(String S,String T,int pos)
    {
    	int i=pos;
    	//i用于主串S中当前位置下标,若pos不为1,则从pos位置开始匹配
    	int j=1;
    	while(i<=S[0]&&j<=T[0])
    	{//S[0]和T[0]存储了两串的长度
    		if(S[i]==T[i])
    		{
    			i++;
    			j++;
    		}
    		else
    		{
    			i=i-j+2;
    			//i退回到上次匹配首位的下一位
    			j=1;
    			//j退回到子串T的首位
    		}
    	}
    	if(j>T[0]) return i-T[0];
    	else return 0;
    }
    
  • 相关阅读:
    Tye exception
    DataSeeder
    angular
    认证Authentication
    MVC
    Ef Core
    工作单元
    VirtualFileSystem
    中间件
    日志
  • 原文地址:https://www.cnblogs.com/AlexKing007/p/12339442.html
Copyright © 2020-2023  润新知