日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

HDU 2087剪花布条 KMP

發布時間:2025/7/14 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 2087剪花布条 KMP 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

KMP算法入門題 ?哥第一次寫KMP慚愧啊,慚愧getnext寫得蛋痛,后面的KMP部分更蛋痛。改了N久

#include<stdio.h> #include<string.h> #define Max 1005 char str[Max+5] = {0},ch[Max+5] = {0}; int next[Max+5],count = 0,n; void getnext( ) {int i = 0,j = -1;next[0] = -1;while( ch[i] ){if( j == -1 || ch[i] == ch[j] )++i,++j,next[i] = j;elsej = next[j];}n = i; } void KMP( ) {int i = 0, j = 0;while( str[i] ){if( j == -1 || str[i] == ch[j] )++j,++i; while( str[i] && ch[j] && str[i] == ch[j] )++i,++j;if( j == n )++count,j = 0;elsej = next[j];} } int main( ) {while( scanf( "%s",str ),str[0] != '#' ){scanf( "%s",ch );n = count = 0;getnext( );KMP( );printf( "%d\n",count );}return 0; }

這是final版。。。改了好久啊。。。

轉載于:https://www.cnblogs.com/Lvsi/archive/2011/02/01/1948621.html

總結

以上是生活随笔為你收集整理的HDU 2087剪花布条 KMP的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。