下载了样例点1Dev运行结果与答案一样但过不了
查看原帖
下载了样例点1Dev运行结果与答案一样但过不了
577581
00000110hh楼主2022/8/3 16:37

下载了样例点1Dev运行结果与答案一样但过不了

//瞻前顾后,莫改已求的答案(p)
#include<bits/stdc++.h>
using namespace std;
char st[11],ar[1000100];
int ans;
int p;// The first location of the occurrence
int slen;// The lenth of the word to find
bool f;// To fix the value of the "p"
bool check(char a,char b){
	if((a>='a'&&b>='a'&&a==b)||(a<'a'&&b<'a'&&a==b)||(a<'a'&&b>='a'&&'a'+a-'A'==b)||(b<'a'&&a>='a'&&'a'+b-'A'==a)) return 1;
	//ascii先大写后小写 
	return 0;
}
void dfs(int c,int s){
	if(c==slen){
		if(ar[s]==' '){
			ans++;
			f=1;
		}
		return;
	}
	if(c==0){
		for(int i=0;i<strlen(ar);i++){
			if((ar[i-1]==' '||i==0)&&check(st[c],ar[i])){
				if(!f) p=i;
				dfs(c+1,i+1);	
			} 
		}	
		return;
	}
	else if(check(st[c],ar[s])) dfs(c+1,s+1);
	else return;
}
int main(){
//	gets(st);
	cin>>st;
	fflush(stdin);
	gets(ar);
	slen=strlen(st);
	dfs(0,0);
	if(ans==0) cout<<-1;
//	else cout<<ans<<" "<<p<<endl;
//	else cout<<"1 2";
	else printf("%d %d" , ans, p);
	return 0;
}

1in:

td
  Td tLWCsrmt

1out:

1 2

求助大佬!!!

2022/8/3 16:37
加载中...