2 条题解

  • 0
    @ 2023-11-22 15:32:15
    #include <iostream>
    #include <string>
    using namespace std;
    int main() {
    	string a, b;
    	int sum = 0;
    	getline(cin, a);
    	getline(cin, b);
    	if (b.find(a) != string::npos) {
    		cout << a << " is substring of " << b << endl;
    		return 0;
    	}
    	else if (a.find(b) != string::npos) {
    
    		cout << b << " is substring of " << a << endl;
    	}
    	else
    		cout << "No substring";
    	return 0;
    }
    
    • 0
      @ 2023-11-16 12:36:07
      #include<stdio.h>
      #include<string.h>
      int judge(char a[],char b[],int l1,int l2);
      int main()
      {
          char a[201],b[201];
          gets(a);
          gets(b);
          int rec;
          int l1=strlen(a);
          int l2=strlen(b);
          if(l1>=l2)
          rec=judge(a,b,l1,l2);
          else if(l1<l2)
          rec=judge(b,a,l2,l1);
          if(rec)
          {
              if(l1>=l2)
              printf("%s is substring of %s",b,a);
              else if(l1<l2)
              printf("%s is substring of %s",a,b);
          }
          else
          printf("No substring");
          return 0;
      }
      int judge(char a[],char b[],int l1,int l2)
      {
          int i,j;
          int count=0;
          int flag=0;
      	int n=0;
          for(i=0;i<l1;i++)
          {
              if(a[i]==b[n])
              {
              n++;
              count++;
              if(count==l2)
              {
              flag=1;
              break;
              }
              }
              else
              { 
              count=0;
              n=0;
              }
          }
          return flag;
      }
      
      • 1

      信息

      ID
      141
      时间
      1000ms
      内存
      128MiB
      难度
      7
      标签
      (无)
      递交数
      922
      已通过
      187
      上传者