zoukankan      html  css  js  c++  java
  • 非KMP字符串匹配实现

     1 #include <iostream>
     2 using namespace std;
     3 
     4 #define MAXLINE 1000
     5 //读取一行输入
     6 int getline(char s[] ,int limit)
     7 {
     8     int c,i;
     9     i = 0;
    10     while ((c = getchar()) != EOF && c != '
    ' && --limit > 0 )
    11     {
    12         s[i++] = c;
    13     }
    14 
    15     if (c == '
    ')
    16     {
    17         s[i] = '';
    18     }
    19     return i;
    20 }
    21 
    22 //返回s中与t首次匹配的位置,否则返回-1
    23 int strindex(char s[] ,char t[])
    24 {
    25     int i,j,k;
    26     for (i = 0 ; s[i] !=''; i++)
    27     {
    28         for (j = i,k = 0;t[k] !='' && s[j] == t[k] ;j++,k++)
    29         {
    30             ;
    31         }
    32         if (k>0 && t[k] == '')
    33         {
    34             return i;
    35         }
    36 
    37     }
    38     
    39     
    40     return -1;
    41 }
    42 
    43 void main()
    44 {
    45     char line[MAXLINE];
    46     while (getline(line,MAXLINE) > 0)
    47     {
    48         if (strindex(line,"ould") >= 0 )
    49         {
    50             //printf("%s
    ",line);
    51             cout<<line<<endl;
    52         }
    53     }
    54 }
  • 相关阅读:
    线程高并发
    29(套接字)就是网络编程
    28线程
    27 枚举
    26静态导入和可变参数
    25JDK新特性
    25断言 assert关键字
    24单元测试 junit
    炫酷CSS
    PHP 汉字转拼音类
  • 原文地址:https://www.cnblogs.com/yaoxc/p/3324799.html
Copyright © 2011-2022 走看看