Last active
March 22, 2019 12:39
-
-
Save maehrm/7d1963324b6b77687a8e56dcd5debb87 to your computer and use it in GitHub Desktop.
平成20年度春期試験_基本情報午後問2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
平成20年度春季基本情報午後問2 - Mae向きなブログ