Home > Back-end >  String matching
String matching

Time:09-25

OJ has been through the great god, please look!

Given two strings S and T, please decide whether T is S substring, ontology, please use "of" simple matching method to do submit AC observation Exe. After the Time, and with DS16, DS17 comparison, using the system language built-in function judgment, will not write their own functions, sentenced to cheat, titles,

Input
The first line is an integer N, indicating how many test cases,

Followed by N test cases, each test case of line 2: the first line is the string S, the second line is a string, the string does not contain Spaces, 1 or less strlen (S), strlen (T), 10000 or less

The Output
For each test case, output a line: whether the substring, is the output "yes", otherwise output "no"

The Sample Input
2
Aabcdd
ABC
Aaaaaaaaaaaaa
Aaaaaab

The Sample Output
Yes
No



Here is my code:
# include
# include

Int main (void)
{
Char S [10005];
Char T [10005];
Int a, b, c;
Int N;
Char ch;
int i=0;

The scanf (" % d ", & amp; N);
Ch=getchar ();
While (iGets (S);
Gets (T);
If (strlen (S)==NULL | | strlen (T)==NULL) {printf (" no \ n "); }
The else {
For (a=0, b=0, c=0; A{
If (S [a]! [b]) b=T=0;

If (S [a] [b]==T) b++;

If (b==strlen (T)) {c + +; break; }
}

If (c!=0) printf (" yes \ n ");
The else printf (" \ n ");
}
i++;

}

return 0;

}



CodePudding user response:

1. Getchar is in receiving what character? I can't see in your request
2. A number cannot use strlen returns NULL, use digital judgment
3. The judge substring which string should be short, and you just have to cope with it as a substring

CodePudding user response:

If (S [a]! [b]) b=T=0;
Else if (S [a] [b]==T) b++;

Should because of this the else, changed to see

CodePudding user response:

NO problem can be done by your algorithm, because you have the determination of the if statement nested in the while loop, so every time after the match, are YES/NO decision output

CodePudding user response:

I changed but or not...
# include
# include

Int main (void)
{
Char S [10005];
Char T [10005];
Int a, b, c;
Int N;
Char ch;
int i=0;

The scanf (" % d ", & amp; N);
Ch=getchar ();
While (iGets (S);
Gets (T);
If (strlen (S)==0 | | strlen (T)==0) {printf (" no \ n "); }
If (strlen (S) & gt;=strlen (T))
{
For (a=0, b=0, c=0; A{
If (S [a]! [b]) b=T=0;

If (S [a] [b]==T) b++;

If (b==strlen (T)) {c + +; break; }
}

If (c!=0) printf (" yes \ n ");
The else printf (" \ n ");
}
The else printf (" \ n ");
i++;

}

return 0;

}



  • Related