2 solutions

  • 2
    @ 2024-8-7 18:08:28
    #include <bits/stdc++.h>
    using namespace std;
    int main() {
    	string s, c;
    	cin >> c;
    	getchar();
    	getline(cin, s);
    	for (int i = 0; i < c.size(); i++) {
    		c[i] = tolower(c[i]);
    	}
    	for (int i = 0; i < s.size(); i++) {
    		s[i] = tolower(s[i]);
    	}
    	c = ' ' + c + ' ';
    	s = ' ' + s + ' ';
    	if (s.find(c) == string::npos) {
    		cout << "-1";
    		return 0;
    	}
    	int firstpos = s.find(c);
    	int pos = firstpos;
    	int ans = 0;
    	while (pos != string::npos) {
    		ans++;
    		pos = s.find(c, pos + 1);
    	}
    	cout << ans << " " << firstpos;
    	return 0;
    }
    
    • 1
      @ 2024-12-2 21:26:20
      #include<bits/stdc++.h>
      typedef long long ll;
      using namespace std;
      const int N=10010;
      char a[1000000];
      char b[1000];
      char c[1000];
      int s;
      bool f=1;
      int i,l,n,l2,t;
      int main() {
      
      	cin.sync_with_stdio(false);
      	ios::sync_with_stdio(0);
      	cin.tie(0);cout.tie(0);
      	cin.getline(b,1000);
      	cin.getline(a,1000000);
      //	strupr(a);
      //	strupr(b);
      	l=strlen(a);
      	a[l]=' ';
      	a[l+1]='\0';
      	for(i=0;i<=l;i++){
      		if(a[i]!=' '){
      			c[n]=a[i];
      			n++;
      		} 
      		else{
      			c[n]='\0';
      			if(strcmp(c,b)==0){
      				s++;
      				if(f==1){
      					l2=strlen(c);
      					t=i-l2;
      					f=0;
      				}
      			}
      			n=0;
      		}
      	}
      	if(s==0){
      		cout<<"-1";
      	} 
      	else{
      		cout<<s<<' '<<t;
      	}
      	
      	return 0;
      }
      
      • 1

      Information

      ID
      449
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      7
      Tags
      (None)
      # Submissions
      61
      Accepted
      14
      Uploaded By