Home > Back-end >  Jmu data structure of 3 discuss zyy group experiment
Jmu data structure of 3 discuss zyy group experiment

Time:05-11

Assessment of topic 2 - all in one (+ 1)

A) write a function bool isExist (string s1, string s2)
Whether s1 s2 "queue",
B) hint: use the find function of string
C) dealing with input and output of the reference code, isExist is a function of the need to write,
D) test, input and output in the first place in the native copy and paste method tests are available, and then test the following input:
Aaab a, should be the output?

Topic

Bool isExist (string s1, string s2);
Int main ()
{
Strings str1 str2;
While (cin & gt;> Str1 & gt;> Str2)
{
If (isExist (str1, str2))
Cout & lt; <"Yes" & lt; The else
Cout & lt; <"No" & lt; }
return 0;
}

CodePudding user response:

Bool isExist (string s1, string s2)
{
Int jug.
Jug=s1. The find (s2);
If (jug!=1) return true;
The else return false;
}

Directly use the find function to find the s1 s2 is lazy method

CodePudding user response:

Another idea is

Bool isExist (string s1, string s2) {
Int m=s1 length ();
Int n=s2. Length ();
If (n==0) return true;

for (int i=0; i int j=0;
Int t=I;
While (s1==s2 [t] [j] & amp; & J & lt; N) {
j++;
If (s1 [t]! [j]=s2 & amp; & J & lt; N) {
break;
}

}
If (j)==n {
return true;
}
}
return false;
}

CodePudding user response:

The
reference 2 floor ordinary hao response:
another way of thinking is

Bool isExist (string s1, string s2) {
Int m=s1 length ();
Int n=s2. Length ();
If (n==0) return true;

for (int i=0; i int j=0;
Int t=I;
While (s1==s2 [t] [j] & amp; & J & lt; N) {
j++;
If (s1 [t]! [j]=s2 & amp; & J & lt; N) {
break;
}

}
If (j)==n {
return true;
}
}
return false;
}


On the type of annotation

Int m=s1 length ();//calculate the length of the string
Int n=s2. Length ();
While (s1==s2 [t] [j] & amp; & J & lt; N) {//compare various characters are equal to determine whether there is in the s1 s2
If (j==n) {//compared to the first n (s2) [n - 1]
  • Related