#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void prefix_table(char pattern[], int prefix[], int n) {
prefix[0] = 0;
int len = 0;
int i =1;
while(i<n){
if ( pattern[i] == pattern[len] ) {
len++ ;
prefix[i] = len;
i++ ;
}else {
if(len > 0){
len = prefix[ len-1];
}else {
prefix[i] = len;
i++ ;
}
}
}
}
void move_prefix_table(int prefix[], int n) {
int i;
for(i=n-1;i>0;i--){
prefix[i] = prefix[i-1];
}
prefix[0] = -1;
}
int kmp_search( char text[], char pattern[]) {
int n = strlen( pattern);
int m = strlen( text );
int* prefix =(int*)malloc( n*sizeof(int));
prefix_table(pattern, prefix, n);
move_prefix_table(prefix, n);
int i=0;
int j=0;
while(i<m){
if (j==n-1&&text[i]==pattern[j]) {
j=prefix[j];
return 11;
}
if (text[i] == pattern[j]) {
i++;
j++;
}
else {
j= prefix[j];
if (j == -1) {
i++;
j++ ;
}
}
}
}
int main() {
char s[]=" ";
char t[]=" ";
int n;
static int k=0;
int ss,tt;
while(scanf("%s",s)){
scanf("%d",&n);
int *out=(int*)malloc((n)*sizeof(int));
ss=strlen(s);
for(int i=1;i<=n;i++){
scanf("%s",t);
tt=strlen(t);
if(tt!=0 && ss!=0){
if(tt>ss){
if(kmp_search(t,s)==11){
out[k++]=1;
}else{
out[k++]=2;
}
}
else if(ss>tt){
if(kmp_search(s,t)==11){
out[k++]=3;
}else{
out[k++]=4;
}
}
else if(ss == tt){
if(strcmp(s,t)==0){
out[k++]=5;
}else{
out[k++]=6;
}
}
}
}
for(int i=0;i<n;i++){
if(out[i]==3){
printf("my child!\n");
}
if(out[i]==4){
printf("oh,child!\n");
}
if(out[i]==1){
printf("my teacher!\n");
}
if(out[i]==2){
printf("senior\n");
}
if(out[i]==5){
printf("jntm!\n");
}
if(out[i]==6){
printf("friend!\n");
}
}
}
printf("\n");
return 0;
}
main
|
|
|
|
----------java
| |
| |
| |
| |
| |-------org(框架)
| |
| |-------bms
| |
| |
| |-------controller(控制类)
| |
| |-------dao(用于处理前端和数据库之间的信息交换的类)
| |
| |-------entity(封装了每个类的独立信息)
| |
|
|
----------resources
|
|
|
----------webappp
| |
|-------
|
|
|-------
|
|
、 |
|-------WEB-INF
| |
| |
| |-------web.xml
|---------
|
|
|
|-------
|
|
|---------
|
|
acm_kMp
最新推荐文章于 2023-05-10 15:32:27 发布