4 solutions

  • 2
    @ 2024-3-15 14:59:47
    //两个字符串同时往后移动,如果第一个和第二个相同,则继续同时走,否则只有第二个字符串往后走
    
    #include<bits/stdc++.h>
    using namespace std;
    const int N=100010;
    string s1,s2;
    int main()
    {
    	while(cin>>s1>>s2)
    	{
    		int n=s1.size();
    		int m=s2.size();
    		int i=0,j=0,cnt=0;
    		while(i<n&&j<m) //两个都没有走到尾 
    		{
    			if(s1[i]==s2[j]) //相同就同时往后走 
    			{
    				cnt++;
    				i++;
    				j++;
    			}
    			else //只有第二个往后走 
    			{
    				j++;
    			}
    		}
    		if(cnt==n) cout<<"Yes"<<endl;
    		else cout<<"No"<<endl;
    	}
    	return 0;
    }
    
    
    
    • 1
      @ 2025-8-22 15:48:31
      #include<bits/stdc++.h>
      using namespace std;
      const int N=100010;
      string s1,s2;
      int main()
      {
      	while(cin>>s1>>s2)
      	{
      		int n=s1.size();
      		int m=s2.size();
      		int i=0,j=0,cnt=0;
      		while(i<n&&j<m)
      		{
      			if(s1[i]==s2[j])
      			{
      				i++;
      				j++;
      				cnt++;
      			}
      			else
      			{
      				j++;
      			}
      		} 
      		if(cnt==n) cout<<"Yes"<<endl;
      		else cout<<"No"<<endl; 
      	}
      	
      	return 0;
      }
      
      
      
      • 0
        @ 2025-8-21 14:17:32
        #include<bits/stdc++.h>
        using namespace std;
        string s,t; 
        int main(){
        	while(cin>>s>>t){
        		if(t.find(s)==0){
        			cout<<"No"<<endl;
        		}else{
        			cout<<"Yes"<<endl;
        		}
        	}
        
        
        	return 0;
        }
        
        
      • -1
        @ 2024-12-8 16:15:14
        #include<bits/stdc++.h>
        using namespace std;
        const int N=100010;
        string s1,s2;
        int main()
        {
        	while(cin>>s1>>s2)
        	{
        		int n=s1.size();
        		int m=s2.size();
        		int i=0,j=0,cnt=0;
        		while(i<n&&j<m)
        		{
        			if(s1[i]==s2[j])
        			{
        				i++;
        				j++;
        				cnt++;
        			}
        			else
        			{
        				j++;
        			}
        		} 
        		if(cnt==n) cout<<"Yes"<<endl;
        		else cout<<"No"<<endl; 
        	}
        	
        	return 0;
        }
        
        • 1

        Information

        ID
        80
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        3
        Tags
        (None)
        # Submissions
        49
        Accepted
        20
        Uploaded By