2 条题解

  • 2
    @ 2024-2-4 14:22:36
    #include<bits/stdc++.h>
    using namespace std;
    string a,b,temp; 
    int cmp(string a,string b){
    	int len0 = a.size();
    	int len1 = b.size();
    	if(len0>len1){
    		return 1;
    	}else{
    		return 0;
    	}
    }
    int main(){
    	cin>>a>>b;
    	if(cmp(a,b)){
    		temp = a;
    		a =b;
    		b = temp;
    	}int len = b.size();
    		for(int i = 0; i<len;i++){
    			if(b[i] == a[0]){
    				int  flag = true;
    				for(int j = 0;j<a.size();j++){
    					if(b[i+j] == a[j]){
    						
    					}else {
    						flag = false;
    						break;
    					}
    				}
    				if(flag){
    					cout<<a<<" is substring of "<<b;
    					return 0;
    				}
    			}
    		}
    	cout<<"No substring";
    				
    	return 0;
    }
    
    • 1
      @ 2024-2-4 14:11:23
      #include<bits/stdc++.h>
      using namespace std;
      string a,b,c;
      int main(){
          cin>>a>>b;
          if(a.find(b)!=-1)
          {
          	cout<<b<<" is substring of "<<a;
          }
          else if(b.find(a)!=-1)
      	{
          	cout<<a<<" is substring of "<<b;
          }else 
      	{
      		cout<<"No substring";
      	}
          return 0;
      }
      
      • 1

      信息

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