#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
using namespace std;
int sub(string a, int lena, string b, int lenb);
int main()
{
string s1, s2;
getline(cin, s1);
getline(cin, s2);
int len1 = s1.size();
int len2 = s2.size();
if (len1 > len2)
sub(s1, len1, s2, len2);
else
sub(s2, len2, s1, len1);
return 0;
}
int sub(string a, int lena, string b, int lenb)
{
for (int i = 0; i < lena; i++)
{
if (i + lenb > lena)
{
cout << "No substring" << endl;
return 0;
}
else
{
bool sign;
if (a[i] == b[0])
{
sign = 1;
for (int j = 0; j < lenb; j++)
{
if (a[i + j] != b[j])
sign = 0;
}
if (sign)
{
cout << b << " is substring of " << a << endl;
return 0;
}
}
}
}
return 0;
}
Openjudge 1.7-18.验证子串答案
于 2022-11-07 21:01:12 首次发布