Preface
I wanted to see the question and go to bed directly. I saw that this question was just a question of Beihang's computer. At that time, there were very few people who made it. So I couldn't help but feel excited, I have to talk to one of my colleagues about how to use git on my own. It took me more than 40 minutes to debug and ac, after all, I started to do the question at, so it is inevitable that I will not concentrate on it.
Start Time:
End Time:
Ac process:
Question
[Html]
Description:
Read data string [], and then read a short string. Search for all matches between string [] and short strings, and output line numbers and matched strings. The matching is case-insensitive and can have a pattern match in brackets. For example, "aa [123] bb" means that aa1bb, aa2bb, and aa3bb are all matched.
Input:
Multiple groups of data are input.
Enter n (1 <= n <= 1000) in the first row of each group of data, enter n strings (excluding spaces) from the second row, and then enter a matching string.
Output:
Output the line number of the matched string and the string (case-insensitive ).
Sample input:
4
Aab
A2B
AB
ABB
A [a2b] B
Sample output:
1 Aab
2 a2B
4 ABB
Description:
Read data string [], and then read a short string. Search for all matches between string [] and short strings, and output line numbers and matched strings. The matching is case-insensitive and can have a pattern match in brackets. For example, "aa [123] bb" means that aa1bb, aa2bb, and aa3bb are all matched.
Input:
Multiple groups of data are input.
Enter n (1 <= n <= 1000) in the first row of each group of data, enter n strings (excluding spaces) from the second row, and then enter a matching string.
Output:
Output the line number of the matched string and the string (case-insensitive ).
Sample input:
4
Aab
A2B
AB
ABB
A [a2b] B
Sample output:
1 Aab
2 a2B
4 ABB
Ac code
It's too late. Don't talk about the train of thought, and it's no difficulty. It's just a simulation of regular expressions.
[Cpp]
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
# Deprecision MAX 1001
# Deprecision LEN 101
Struct str
{
Char name [101];
};
Int main ()
{
Struct str strs [MAX];
Struct str t [LEN];
Int I, n, len, j, k, left, right, count, flag;
Char text [LEN], newtext [LEN];
While (scanf ("% d", & n )! = EOF ){
// Receive data
Getchar ();
For (I = 0; I <n; I ++ ){
Scanf ("% s", strs [I]. name );
}
// Receives a text string
Getchar ();
Gets (text );
Len = strlen (text );
For (I = left = right = 0; I <len; I ++ ){
If (text [I] = '['){
Left = I;
} Else if (text [I] = ']') {
Right = I;
Break;
}
}
Count = right-left-1;
If (count <= 0) {// no regular match
For (I = j = 0; I <len; I ++ ){
If (text [I]! = '[' & Text [I]! = ']') {
Newtext [j ++] = text [I];
}
}
Newtext [j] = '\ 0 ';
For (I = 0; I <n; I ++ ){
If (strcasecmp (strs [I]. name, newtext) = 0 ){
Printf ("% d % s \ n", I + 1, strs [I]. name );
}
}
} Else {// regular match required
For (j = 1, k = 0; j <= count; j ++, k ++) {// construct a text Array
Memset (t [k]. name, '\ 0', sizeof (t [k]. name ));
For (I = 0; I <left; I ++ ){
T [k]. name [I] = text [I];
}
T [k]. name [I] = text [left + j];
Strcat (t [k]. name, text + right + 1 );
}
// Regular Expression matching
For (I = 0; I <n; I ++ ){
For (j = flag = 0; j <count; j ++ ){
If (strcasecmp (strs [I]. name, t [j]. name) = 0 ){
Flag = 1;
Break;
}
}
If (flag ){
Printf ("% d % s \ n", I + 1, strs [I]. name );
}
}
}
}
Return 0;
}
/*************************************** ***********************
Problem: 1165
User: wangzhengyi
Language: C
Result: Accepted
Time: 0 MS
Memory: 948 kb
**************************************** ************************/
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
# Deprecision MAX 1001
# Deprecision LEN 101
Struct str
{
Char name [101];
};
Int main ()
{
Struct str strs [MAX];
Struct str t [LEN];
Int I, n, len, j, k, left, right, count, flag;
Char text [LEN], newtext [LEN];
While (scanf ("% d", & n )! = EOF ){
// Receive data
Getchar ();
For (I = 0; I <n; I ++ ){
Scanf ("% s", strs [I]. name );
}
// Receives a text string
Getchar ();
Gets (text );
Len = strlen (text );
For (I = left = right = 0; I <len; I ++ ){
If (text [I] = '['){
Left = I;
} Else if (text [I] = ']') {
Right = I;
Break;
}
}
Count = right-left-1;
If (count <= 0) {// no regular match
For (I = j = 0; I <len; I ++ ){
If (text [I]! = '[' & Text [I]! = ']') {
Newtext [j ++] = text [I];
}
}
Newtext [j] = '\ 0 ';
For (I = 0; I <n; I ++ ){
If (strcasecmp (strs [I]. name, newtext) = 0 ){
Printf ("% d % s \ n", I + 1, strs [I]. name );
}
}
} Else {// regular match required
For (j = 1, k = 0; j <= count; j ++, k ++) {// construct a text Array
Memset (t [k]. name, '\ 0', sizeof (t [k]. name ));
For (I = 0; I <left; I ++ ){
T [k]. name [I] = text [I];
}
T [k]. name [I] = text [left + j];
Strcat (t [k]. name, text + right + 1 );
}
// Regular Expression matching
For (I = 0; I <n; I ++ ){
For (j = flag = 0; j <count; j ++ ){
If (strcasecmp (strs [I]. name, t [j]. name) = 0 ){
Flag = 1;
Break;
}
}
If (flag ){
Printf ("% d % s \ n", I + 1, strs [I]. name );
}
}
}
}
Return 0;
}
/*************************************** ***********************
Problem: 1165
User: wangzhengyi
Language: C
Result: Accepted
Time: 0 MS
Memory: 948 kb
**************************************** ************************/