求助样例过了但是提交错了还超时
查看原帖
求助样例过了但是提交错了还超时
443754
Sender_T楼主2021/3/27 22:39

rt,以下是代码萌新求助

#include<bits/stdc++.h>
using namespace std;
char a[1000001],c[1000001];
int f=0,s,cnt=0,location=0,cnt2=0;
bool ok=false;
bool isEqual(int f,int s){
	for(int i=f,d=0;i<=s;i++){
		if(a[i]!=c[d]){
			return false;
		}
		d++;
	}
	return true;
}
void toLower(char a[]){
	for(int i=0;i<=strlen(a);i++){
		if(a[i]>='A'&&a[i]<='Z'){
			a[i]=((int)a[i])+32;
		}
	}
}
int main(){
	bool right=true;
  gets(c);
  gets(a);
  toLower(c);
  toLower(a);
  for(int i=0;i<=strlen(a);i++){
  	if(a[i]==' ' or a[i]=='\0'){
  		cnt2++;
  		s=i-1;
  		if(isEqual(f,s)){
  			if(right==true){
  				location=cnt2;
  				right=false;
			  }
  			cnt++;
		  }
		  f=i+1;
	  }
  }
  if(cnt==0){
  	cout<<-1<<endl;
  }else cout<<cnt<<" "<<location-1<<endl;
  return 0;
}
2021/3/27 22:39
加载中...