60分求助 5,7,8,9WA
查看原帖
60分求助 5,7,8,9WA
427110
Logiking楼主2021/3/29 16:01
#include<iostream>
#include<string>
using namespace std;
string x,y;
int x1,y1;
int main(){
	getline(cin,x);
	getline(cin,y);
	x1 = x.length() ;
	y1 = y.length() ;
	int i;
	for(i = 0; i < x1; i++){
		x[i] = toupper(x[i]);
	}
	for(i = 0; i < y1; i++){
		y[i] = toupper(y[i]);
	}
	int j;
	int t = 0,ans = 0;
	for(i = 0; i <= y1 - x1; i++){
		for(j = 0; j < x1; j++){
			if(y[i+j] != x[j])break;
			if(i > 0 && y[i-1] != ' ')break;
			if(j == x1 -1){
				t++;
				if(t == 1)ans = i;
			}
		}
	}
	if(t == 0){
	cout << -1 ;
	return 0;}
	cout << t << " " << ans << endl;
	return 0;
}
2021/3/29 16:01
加载中...