#include <stdio.h>
#include<stdlib.h>
#define MAXLINE 1000;
void shellsort(int v[], int n);
int getline(char line[], int max);
int strindex(char source[], char searchfor[]);
int binsearch(int x, int v[], int n);
char pattern[] = "ould";//当前行需要匹配到的字符串,若匹配到则打印该行
int main() {
/*int v[] = { 49,38,65,97,76,13,27,49,55,04 };
shellsort(v, 10);
for (int i = 0; i < 10; i++) {
printf("%6d ", v[i]);
}
getchar();*/
char line[1000];
int found = 0;
while (getline(line, 1000) > 0) {//反复读取一行
if (strindex(line, pattern) >= 0) {//读取的一行进行模式匹配
printf("%s", line);
found++;
}
return found;
}
}
//二分查找方法
int binsearch(int x, int v[], int n) {
int low, high, mid;
low = 0;
high = n - 1;
while (low <= high) {
mid = (low + high) / 2;
if (x < v[mid]) {
high = mid - 1;
}
else if (x > v[mid]) {
low = mid + 1;
}
else {
return mid;
}
}
return -1;
}
void shellsort(int v[], int n)
{
int gap, i, j, temp;//gap为增量
for (gap = n / 2; gap > 0; gap /= 2)//最外层循环为增量的变化,从n/2一直到增量为1,最后一次增量一定为1
for (i = 0; i < n - gap; i++)//该循环为第二层循环,实际上该循环的作用是辅助第三层的直接插入排序
for (j = i; j >= 0 && v[j] > v[j + gap]; j -= gap) {//该循环实际上就是间隔增量下的直接插入排序,j的变化需要第二层循环的辅助
temp = v[j];
v[j] = v[j + gap];
v[j + gap] = temp;
}
}
int getline(char s[], int lim) {
int c, i;
i = 0;
while (--lim > 0 && (c = getchar()) != EOF && c != '\n')
s[i++] = c;
if (c == '\n')
s[i++] = c;
s[i] = '\0';
return i;
}
int strindex(char s[], char t[]) {
int i, j, k;
for (i = 0; s[i] != '\0'; i++) {//要搜索的那一行
for (j = i, k = 0; t[k] != '\0' && s[j] == t[k]; i++, k++);
if (k > 0 && t[k] == '\0')
return i;
}
return -1;
}