5 solutions

  • 5
    @ 2023-12-25 20:25:45
    #include <bits/stdc++.h>
    using namespace std;
    string a,b;
    int main(){
        cin>>a>>b;
        if(a.find(b)!=a.npos) cout<<b<<" is substring of "<<a<<endl;
        else if(b.find(a)!=b.npos) cout<<a<<" is substring of "<<b<<endl;
        else cout<<"No substring"<<endl;
        return 0;
    }
    

    函数,启动!!!

    • 2
      @ 2023-11-9 18:59:53
      #include <bits/stdc++.h>
      using namespace std;
      string s1, s2;
      int main() {
          cin >> s1 >> s2;
          int strLength = s1.length();
          int subLength = s2.length();
          for (int i = 0; i <= strLength - subLength; i++) {
              bool found = true;
              for (int j = 0; j < subLength; j++) {
                  if (s1[i + j] != s2[j]) {
                      found = false;
                      break;
                  }
              }
              if (found) {
                  cout << s2 << " is substring of " << s1;
                  return 0;
              }
          }
          strLength = s2.length();
          subLength = s1.length();
          for (int i = 0; i <= strLength - subLength; i++) {
              bool found = true;
              for (int j = 0; j < subLength; j++) {
                  if (s2[i + j] != s1[j]) {
                      found = false;
                      break;
                  }
              }
              if (found) {
                  cout << s1 << " is substring of " << s2;
                  return 0;
              }
          }
          cout << "No substring";
          return 0;
      }
      
      
      • 0
        @ 2024-11-12 18:51:51
        #include<bits/stdc++.h>
        using namespace std;
        string s1,s2;
        int main(){
            cin>>s1>>s2;
            if(s1.size()<s2.size()){
                swap(s1,s2);
            }
            if(s1.find(s2)==-1){
                cout<<"No substring";
            }else{
                cout<<s2<<" is substring of "<<s1;
            }
            return 0;
        }
        
        
        • 0
          @ 2023-10-3 14:41:28
          ```
          #include<bits/stdc++.h>
          using namespace std;
          string a,b;
          int main()
          {
              cin>>a>>b;
              if(a.find(b)!=a.npos)    //如果b是a的子串 
              {
                  cout<<b<<" is substring of "<<a<<endl;
              }
              else if(b.find(a)!=b.npos)   //如果a是b的子串 
              {
                  cout<<a<<" is substring of "<<b<<endl;
              }
              else      //如果没有子串关系 
              {
                  cout<<"No substring"<<endl;
              }
              return 0;
          }
          
          • -1
            @ 2023-10-4 16:22:54

            #include<bits/stdc++.h> using namespace std; bool StrSubCompare(string s1,string s2){ int lens1=int(s1.size()); int lens2=int(s2.size()); if(lens1>=lens2){ for(int i=0;i<lens1;i++){ if(s2[0]s1[i]){ for(int x=0;x<lens2;x++){ if(s2[x]!=s1[i+x]){ break; } else if(xlens2-1&&s2[x]==s1[i+x]){ return true; } } } } } else{ return false; }

            } int main(){ string str1,str2; getline(cin,str1); getline(cin,str2); if(StrSubCompare(str1,str2)==true){ cout<<str2<<" "<<"is substring of "<<str1; } else if(StrSubCompare(str2,str1)==true){ cout<<str1<<" "<<"is substring of "<<str2; } else{ cout<<"No substring"; } return 0; }

            • 1

            Information

            ID
            626
            Time
            1000ms
            Memory
            256MiB
            Difficulty
            6
            Tags
            # Submissions
            129
            Accepted
            43
            Uploaded By