Nine-degree machine Test topic 1165: String Match 2008 the computer research of Beihang University and its real problem

Source: Internet
Author: User

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]!= ' [' &&amp            ; 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<< "" &lt                    ;<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

Related Article

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.