3 条题解

  • 7
    @ 2021-10-16 21:16:09
    #include <stdio.h>
    #include <iostream>
    #include <string.h>
    using namespace std;
    char s[1005],a[105],b[105];
    int main()
    {
    	cin.getline(s,1000);
    	cin >> a;
    	cin >> b;
    	int len = strlen(s);
    	int lena = strlen(a);
    	for(int i = 0 ; i < len ; i++)
    	{
    		if(i == 0 || s[i-1] == ' ')
    		{
    			int id1,id2;
    			id1 = i;
    			id2 = 0;
    			while(s[id1] == a[id2] && id2 < lena && id1 < len)
    			{
    				id1++,id2++;
    			}
    			if( id2 == lena && (s[id1] == ' ' || s[id1] == '\0') )
    			{
    				cout << b;
    				if(s[id1] != '\0')
    					cout << " ";
    				i = id1;
    				continue;
    			}
    			cout << s[i];
    			
    		}
    		else 
    		{
    			cout << s[i];
    		}
    	}
    	// cout << endl;
    }
    
    • 2
      @ 2025-3-21 20:12:49
      
      #include<bits/stdc++.h>
      using namespace std;
      const int N=1e5+10;
      const int INF=0x3f3f3f3f;
      int main(){
      	string s,a,b;
      	getline (cin,s);
      	cin>>a>>b;
      	s=" "+s+" ";
      	a=" "+a+" ";
      	b=" "+b+" ";
      	while(s.find(a)!=string::npos){
      		s.replace(s.find(a),a.size(),b);
      	}
      	for(int i=1;i<s.size()-1;i++){
      		cout<<s[i];
      	}
      }
      
      • -1
        @ 2024-5-12 20:18:57
        #include <iostream>
        #include<cstring>
        #include<bits/stdc++.h>
        using namespace std;
        char k[1145],a[114],b[114];
        int main()
        {
        	cin.getline(k,1000);
        	cin >> a;
        	cin >> b;
        	int len = strlen(k);
        	int lena = strlen(a);
        	for(int i = 0 ; i < len ; i++)
        	{
        		if(i == 0 || k[i-1] == ' ')
        		{
        			int id1,id2;
        			id1 = i;
        			id2 = 0;
        			while(k[id1] == a[id2] && id2 < lena && id1 < len)
        			{
        				id1++,id2++;
        			}
        			if( id2 == lena && (k[id1] == ' ' || k[id1] == '\0') )
        			{
        				cout << b;
        				if(k[id1] != '\0')
        					cout << " ";
        				i = id1;
        				continue;
        			}
        			cout << k[i];
        			
        		}
        		else 
        		{
        			cout << k[i];
        		}
        	}
        }
        
        • 1

        信息

        ID
        1098
        时间
        1000ms
        内存
        256MiB
        难度
        7
        标签
        递交数
        428
        已通过
        114
        上传者