蒟蒻求救c⌒っ゚Д゚)っ
  • 板块灌水区
  • 楼主dza2
  • 当前回复6
  • 已保存回复7
  • 发布时间2023/10/26 21:00
  • 上次更新2023/11/2 11:17:44
查看原帖
蒟蒻求救c⌒っ゚Д゚)っ
1072919
dza2楼主2023/10/26 21:00

https://www.luogu.com.cn/problem/P1308

#include<bits/stdc++.h>
using namespace std;
char s[11],t[1000001],ch;
int n,m,cnt,pos;
int main(){
	scanf("%s",s);
	n=strlen(s);
	scanf("%c",&ch);
	while(true){
		scanf("%c",&ch);
		t[m]=ch;
		if(ch=='\n'){
			break;
		}
		m++;
	}
	for(int i=0;i<n;i++){
		if(s[i]>='A'&&s[i]<='Z'){
			s[i]=s[i]-'A'+'a';
		}
	}
	for(int i=0;i<m;i++){
		if(t[i]>='A'&&t[i]<='Z'){
			t[i]=t[i]-'A'+'a';
		}
	}
	pos=-1;
	for(int i=0;i<m;i++){
		if(i+n-1>=m){
			break;
		}
		bool match=true;
		for(int j=0;j<n;j++){
			if(t[i+j]!=s[j]){
				match=false;
				break;
			}
		}
		if(i!=0&&t[i-1]!=' '){
			match=false;
		}
		if(i+n<m&&t[i+n]!=' '){
			match=false;
		}
		if(match){
			cnt++;
			if(pos==-1){
				pos=i;
			}
		}
	}
	if(pos==-1){
		printf("-1");
	}else{
		printf("%d %d",cnt,pos);
	}
}
2023/10/26 21:00
加载中...