Problem: Engine-string

Topic
description Google, Baidu and other search engines have become an integral part of the Internet. In this question, your task is also to design a search engine for searching papers. Of course, the requirements of this question are much less than the actual requirements.
The input to this question will first give a series of papers, for each paper first the title, and then the number of times it has been cited. Then there will be a series of search queries asking which papers have specific keywords in their titles.
Each query may contain multiple keywords, and you need to find papers whose titles contain all the keywords.
"Contains" must be a word in the title that is exactly the given keyword, case-insensitive.
For each query, output the titles of papers that meet the criteria in order of citation counts. If there are papers with the same number of citations, they are sorted in the order in which the papers are listed in the input, with the papers given first come first.
Inputs
Inputs contain multiple sets of data.
The first line of each set of data contains an integer N (1<=N<=1000), which indicates the number of papers, and N=0 indicates the end of the input. The first line of information for each group of papers is the title of the paper, consisting of letters (both upper and lower case) and spaces, no more than 10 words, each word no more than 20 characters, and the title no more than 250 characters in total. The second line is an integer K (0<=K<=108), indicating the number of times it was referenced. After the end of the paper information, there is a line containing an integer M (1<=M<=100), indicating the number of queries. Next there are M lines, each line is a query, consisting of L (1<=L<=10) words separated by spaces, each word does not exceed 20 characters.
Output
For each query, output the titles of papers that satisfy the conditions in the order given by the titles; if there are no papers that satisfy the conditions, do not output. Output a line of " * " after the output of each set of queries, and output a line of "—" after the output of each set of data.
Sample input
6
Finding the Shortest Path
120
Finding the k Shortest Path
80
Find Augmenting Path in General Graph
80
Matching in Bipartite Graph
200
Finding kth Shortest Path
50
Graph Theory and its Applications
40
6
shortest path
k shortest path
graph
path
find
application
0
样例输出
Finding the Shortest Path
Finding the k Shortest Path
Finding kth Shortest Path


Finding the k Shortest Path


Matching in Bipartite Graph
Find Augmenting Path in General Graph
Graph Theory and its Applications


Finding the Shortest Path
Finding the k Shortest Path
Find Augmenting Path in General Graph
Finding kth Shortest Path


Find Augmenting Path in General Graph


*

AC code

#include <iostream>
#include<algorithm>
using namespace std;
struct s{
    string heading;
    int _count;
};
struct s node[1000];
bool compare(s a,s b){
    if(a._count>b._count)
        return true;
    else
        return false;
}
int main()
{
    int n,p;
    while(cin>>n&&n!=0){
        p=0;
        while(n--){
            cin.get();
            getline(cin,node[p].heading);
            cin>>node[p]._count;
            p++;
        }
        int m;
        cin>>m;
        cin.get();
        while(m--){
            string findstr;int sum=0;
            struct s result[1000];
            getline(cin,findstr);
            int len=findstr.size();
            for(int i=0;i<p;i++){
                int lenb=node[i].heading.size();
                int flag;
                for(int x=0;x<lenb;x++){
                    flag=1;
                    for(int j=0;j<len;j++){
                        if(findstr[j]!=node[i].heading[x+j]&&findstr[j]!=node[i].heading[x+j]-32&&findstr[j]!=node[i].heading[x+j]+32){
                            flag=0;
                            break;
                        }
                        if(isalpha(node[i].heading[x+len])){
                            flag=0;
                            break;
                        }
                    }
                    if(flag){
                        result[sum].heading=node[i].heading;
                        result[sum]._count=node[i]._count;
                        sum++;
                        break;
                    }
                }
            }
            sort(result,result+sum,compare);
            for(int k=0;k<sum;k++){
                cout<<result[k].heading<<endl;
            }
            cout<<"***"<<endl;
        }
        cout<<"---"<<endl;
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325805836&siteId=291194637