3 条题解

  • 1
    @ 2025-11-30 9:16:58

    用map性质暴力求解

    #include<bits/stdc++.h>
    using namespace std;
    map<queue<char>,int>qq;
    int main()
    {
    	string s1,s2;
    	while(1)
    	{
    		cin>>s1;
    		if(s1=="#")return 0;
    		cin>>s2;
    		int i;
    		queue<char>q1,q2;
    		int cnt=0;
    		for(i=0;i<s2.size();i++)
    		{
    			q2.push(s2[i]);
    		}
    		qq[q2]=1;
    		for(i=0;i<s1.size();i++)
    		{
    			q1.push(s1[i]);
    			if(qq[q1]==1)
    			{
    				cnt++;
    				while(!q1.empty())q1.pop();
    			}
    			if(q1.size()==s2.size())
    			{
    				q1.pop();
    			}
    		}
    		qq[q2]=0;
    		cout<<cnt<<endl;
    	}
    } 
    
    • 0
      @ 2024-12-24 9:49:41

      C++ :

      #include <iostream>
      #include <string>
      using namespace std;
      
      int main(){
      	string str1,str2;
      	int i,pos,len1,len2;
      	while(true){
      		int cnt=0;
      		cin>>str1;
      		if(str1=="#") break;
      		cin>>str2;
      		len2=str2.length();
      		pos=str1.find(str2);
      		while(pos!=-1){
      			pos=str1.find(str2,pos+len2);
      			cnt++;
      		}
      		cout<<cnt<<endl;
      	} 
      }
      
      
      • -2
        @ 2025-11-30 8:38:13

        贪心即可。

        #include<iostream>
        using namespace std;
        string big,sma;
        signed main(){
        	while(cin>>big&&big!="#"){
        		cin>>sma;
        		int ans=0,pos=0,len=sma.size();
        		while((pos=big.find(sma,pos))!=string::npos)ans++,pos+=len;
        		cout<<ans<<'\n';
        	}
        }
        
        • 1

        信息

        ID
        1022
        时间
        1000ms
        内存
        128MiB
        难度
        1
        标签
        (无)
        递交数
        25
        已通过
        36
        上传者