60分,求调
查看原帖
60分,求调
1540454
llllllllll0楼主2024/11/6 08:47
#include <stdio.h>
#include <string.h>
#include <ctype.h>

void low( char*a );
int main(){
	char key_word[11];
	char text[100001];
	scanf("%10s",key_word);
	scanf(" %100000[^\n]",text);
	low( key_word );
	low( text );
	int count = 0;
	int first = -1;
	int w_len = strlen( key_word );
	int t_len = strlen( text );
	for ( int i=0;i<=t_len-w_len;i++ ){
		if ( strncmp(&text[i],key_word,w_len)==0 ){
			if ((i == 0 || (i > 0 && isspace(text[i - 1]))) && (i + w_len == t_len || (i + w_len < t_len && isspace(text[i + w_len])))){
				count ++;
				if ( first==-1 ){
					first = i;
				}
			}
		}
	}
	if ( count ){
		printf("%d %d",count,first);
	}else{
		printf("-1");
	}
	return 0;
}

void low( char *a ){
	for ( int i=0;a[i];i++ ){
		a[i] = tolower( a[i] );
	}
}
2024/11/6 08:47
加载中...