Topic 1165: String Matching
time limit:1 seconds
Memory limit:32 MB
Special question: No
submitted:2497
Resolution:858
-
Topic Description Narration:
-
Read in Data string[]. Then read in a short string. Required to find all matches of short string in string[]. The output line number, matching string. The match does not distinguish between uppercase and lowercase, and can have a pattern match in brackets.
such as "AA[123]BB". That means AA1BB, AA2BB, aa3bb are all matched.
-
Input:
-
Enter more than one set of data.
Enter N (1<=n<=1000) for the first row of each set of data. Enter n strings (without spaces) starting from the second line. Next, enter a matching string.
-
Output:
-
The output matches the line number of the string and the string (does not distinguish between uppercase and lowercase when matched).
-
Example input:
-
4aaba2bababba[a2b]b
-
Example output:
-
1 Aab2 a2b4 ABB
-
Source:
- 2008 the computer Research of Beihang University in the real life test
#include <iostream> #include
#include
#include
#include #include
Using namespace Std;int main () {int n=0; while (cin>>n) {string *s=new string[n+1]; String *tmp=new string[n+1]; for (int i=0;i<=n;i++) {cin>>s[i]; Tmp[i]=s[i].substr (0,s[i].length ()); } for (int i=0;i<=n;i++) {for (int j=0;j<s[i].length (); j + +) {if (s[i][j]!= ' [' && ; S[i][j]!= '] s[i][j]=tolower (S[i][j]); }} int pos=0; int Start=s[n].find (' ['); int End=s[n].find ('] '); String Head=s[n].substr (0,start); String Tail=s[n].substr (End+1,s[n].length ()-end); String *result=new string[end-start-1]; for (int i=start+1;i<end;i++) {result[pos]=head+s[n][i]+tail; for (int j=0;j<n;j++) {if (Result[pos].compare (S[j]) ==0) {cout<<j+1<< "" < ;<tmp[j]<<endl; Break }} pos++; }} return 0;} /************************************************************** problem:1165 User: Audemars Momoko language:c++ Res ult:accepted time:0 Ms Memory:1520 kb****************************************************************/
Nine-degree machine Test topic 1165: String Match 2008 the computer research of Beihang University and its real problem