9 degrees OJ--1165 (C ++), 9 degrees oj -- 1165
# Include <iostream>
# Include <string>
# Include <vector>
Using namespace std;
Int main (){
Int n;
While (cin> n ){
Vector <string> vec;
String input;
Int I, j, k;
// Save n strings in vec
For (I = 0; I <n; I ++ ){
Cin> input;
Vec. push_back (input );
}
// Match string stored in match
String match;
Cin> match;
// Convert string match to character array m []
Const char * m;
M = match. c_str ();
Int x, y; // the position where x and y record [and ].
For (I = 0; I <match. size (); I ++ ){
If (m [I] = '['){
X = I;
Continue;
}
If (m [I] = ']') {
Y = I;
Break;
}
}
For (k = 0; k <n; k ++) {// match n strings respectively
// Convert the string to be matched to the character array q []
Const char * q;
Q = vec [k]. c_str ();
J = 0; // For each matching string, j starts from 0.
Int flag = 0; // enter the range [], flag = 1
Int mon = 0; // match, mon = 1; not match, mon = 0
For (I = 0; I <vec [k]. size (); I ++ ){
If (flag = 1 & j = y ){
Continue;
}
// If q [I] is a lowercase letter
If (int) q [I]> = 97 & (int) q [I] <= 122 ){
// When '[' is not matched
If (flag = 0 ){
// If the character matches
If (int) q [I] = (int) m [j] | (int) q [I]-32 = (int) m [j]) {
Mon = 1;
J ++;
// Determine whether m [j] is '[' at this time '['
If (m [j] = '['){
Flag = 1;
J ++;
}
Continue;
}
// If the character does not match
Else {
Mon = 0;
Break;
}
}
Else {// match a character in []
If (int) q [I] = (int) m [j] | (int) q [I]-32 = (int) m [j]) {
Flag = 0;
J = y + 1;
Continue;
}
Else {
Flag = 1;
J ++;
I --;
Continue;
}
}
}
// If q [I] is a capital letter
Else if (int) q [I]> = 65 & (int) q [I] <= 90 ){
// When '[' is not matched
If (flag = 0 ){
// If the character matches
If (int) q [I] = (int) m [j] | (int) q [I] + 32 = (int) m [j]) {
Mon = 1;
J ++;
// Determine whether m [j] is '[' at this time '['
If (m [j] = '['){
Flag = 1;
J ++;
}
Continue;
}
// If the character does not match
Else {
Mon = 0;
Break;
}
}
Else {// match a character in []
If (int) q [I] = (int) m [j] | (int) q [I] + 32 = (int) m [j]) {
Flag = 0;
J = y + 1;
Continue;
}
Else {
Flag = 1;
J ++;
I --;
Continue;
}
}
}
// If q [I] is neither a lowercase letter nor an uppercase letter
Else {
// When '[' is not matched
If (flag = 0 ){
// If the character matches
If (int) q [I] = (int) m [j]) {
Mon = 1;
J ++;
// Determine whether m [j] is '[' at this time '['
If (m [j] = '['){
Flag = 1;
J ++;
}
Continue;
}
// If the character does not match
Else {
Mon = 0;
Break;
}
}
Else {// match a character in []
If (int) q [I] = (int) m [j]) {
Flag = 0;
J = y + 1;
Continue;
}
Else {
Flag = 1;
J ++;
I --;
Continue;
}
}
}
}
// If the string matches from start to end, mon = 1
If (mon = 1 & j = match. size ()){
Cout <k + 1 <"";
For (I = 0; I <vec [k]. size (); I ++ ){
Cout <q [I];
}
Cout <endl;
}
}
}
Return 0;
}