30pts求助
查看原帖
30pts求助
341245
xrk2006楼主2020/10/31 11:25

WA了7个点,我真的好菜 代码如下:

#include<bits/stdc++.h>
using namespace std;
int len=-1,f,l;
bool found;
int main()
{
	string s,x;
	int h,k=-2;
	getline(cin,x);
	getline(cin,s);
	for(int i=0;i<s.size();i++)
	{
		if(s[i]==' '){h=k+1;k=i-1;}
		else if(i==s.size()-1){h=k+1;k=i;}
		else continue;
		found=false;
		len++;
	    if(k-h==x.size())
	    {
	    	for(int j=h+1,d=0;j<=k;j++,d++)
	    	{
	    		if(x[d]==s[j]||s[j]-32==x[d]||x[d]-32==s[j])
				{
	    			if(j==k){found=true;f++;} 
	    			continue;
				}
	    		break;
			}
			if(f==1&&found==true) l=len;
		}
	}
	if(f!=0)cout<<f<<" "<<l;
	else cout<<"-1";
	return 0;
}
2020/10/31 11:25
加载中...