9 degrees OJ--1165 (C ++), 9 degrees oj -- 1165

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.