30分求解!!测试能通过,求佬!!!
查看原帖
30分求解!!测试能通过,求佬!!!
1258409
chj123123楼主2024/1/15 22:28
//#include<bits/stdc++.h>
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	char s[1000],c[1000];
	int t=0;
	cin.getline(s,1000);
	cin.getline(c,1000);
	int ls=strlen(s);//短的 
	int lc=strlen(c);//长的 
	int num=0,first=0;
	int a=0;
	for(a=0;a<=ls;a++){//大小写转换
		s[a]=tolower(s[a]);
	}
	for(a=0;a<=ls;a++){
		c[a]=tolower(c[a]);
	}
	
	for(int i=0;i<lc;i++){
		int k1=i;
		int k2=0;
			while(c[k1++]==s[k2++]){//比较
			if(k2==ls) {
			num++;
			if(t==0){//记录第一次匹配成功位置
				first=k1-ls;
				t=1;
			}
			 }     
			}
	}
	if(num==0)cout<<"-1";
	else cout<<num<<" "<<first<<endl; 
	//cout<<ls<<" "<<lc;
	return 0; 
}
2024/1/15 22:28
加载中...