Skip to content

Instantly share code, notes, and snippets.

@maehrm
Last active March 22, 2019 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maehrm/7d1963324b6b77687a8e56dcd5debb87 to your computer and use it in GitHub Desktop.
Save maehrm/7d1963324b6b77687a8e56dcd5debb87 to your computer and use it in GitHub Desktop.
平成20年度春期試験_基本情報午後問2
#include <stdio.h>
#include <string.h>
#define TRUE (1)
#define FALSE (0)
int matchCounter(char [], int , char [], int );
int matchCounter(char sourceText[], int textlen, char pattern[], int patlen) {
int counter, i, j, k;
int matchflg;
counter = 0;
i = 0;
while (i + patlen <= textlen) {
j = i;
k = 0;
matchflg = TRUE;
while ((k < patlen) && matchflg) {
if (sourceText[j] == pattern[k]) {
j++;
k++;
}
else {
matchflg = FALSE;
}
}
if (k == patlen) { /* 設問2 */
counter++;
i += patlen;
}
else {
i++;
}
}
return counter;
}
int main(void) {
char sourceText[] = "ggxgxggggggxggxx";
char pattern[] = "gxg";
printf("%d\n", matchCounter(sourceText, strlen(sourceText),
pattern, strlen(pattern)));
return 0;
}
@maehrm
Copy link
Author

maehrm commented Mar 22, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment