TLE求调
查看原帖
TLE求调
1032652
jiosin楼主2024/1/16 16:53
	#include<iostream>
	#include<string>
	#include<algorithm>
	using namespace std;
	
	int main()
	{
		  // ios::sync_with_stdio(false);
		  // cin.tie(NULL);
		  // cout.tie(NULL);
	      string s;
	      cin >> s;
	      s= ' '+s+' ';
	      transform(s.begin(),s.end(),s.begin(),::tolower);
	      string x = "";
	      while(1)
	      {
	          char a;
	          a = getchar();
	          if(a ==EOF) break;
	          if(a == '\n') continue;
	          if(a == ' ') x = x+' ';
	          else x+=tolower(a);
	      }
	      x = ' ' + x + ' ';
	      //cout << x;
	      int t = 0,ans = -1,ff = 0;
	      int f = 0;
	      while(1)
	      {
	      	    f = x.find(s,f  + 1);
	      	   if(f == -1) break;
	      	    if(ff) {t ++;
	      	                  	//x.erase(0,f + s.size()-1);   
	      	                  	 }
	      	           else {
	      	           //	x.erase(0,f + s.size()-1);
	      	           	ans  = f;
	      	           	t++;
	      	            ff= 1;
	      	           } 
	      }
	      if(ans == -1) cout << ans;
	      else cout << t << " " <<   ans; 
		return 0;
	}
2024/1/16 16:53
加载中...