Brett Favre Diaries filename: favre 
 The sporting world recently underwent a media overload with the Brett Favre story.  The recordbreaking Green Bay Packers quarterback, after initially deciding to retire in March, had second thoughts about his decision in the summer.  Had Green Bay simply let Brett join the team again, this would not have been much of a story.  But, the real saga was quite a bit more complicated. As everyone knows, the media tends to pick individual stories and follows them to no end, much like the O.J. Simpson trial coverage.  ESPN treated the Brett Favre story with the same diligence. 
 
You are a football fan and are interested in the Favre story, but enough is enough.  You are sick and tired of getting insignificant updates such as, "Brett Favre eats hot dog" on your cell phone. You want to write a program for your cell phone so that it filters Brett Favre news and only reports to you important information, namely whenever he travels to a new city. 
 
The Problem: 
 
Given a list of cities, and a log of chronological information (with a date and time) about Brett Favre, isolate the log entries that contain the name of a city (from the list of cities) different from the city mentioned in the previous log entry with a city.  You will be guaranteed that the very first item in the log will contain the name of a city.  From that point on, a new log entry is only printed if it contains the name of a city DIFFERENT than the previous log entry with a city (note that the “previous log entry with a city” may not be the “immediate previous log entry”).  Your job will simply be to print out the lines of the log that should be presented on the cell phone text feed. 
 
Note: A city is only considered to be in a log entry if it appears EXACTLY, character by character, in the log entry.  Namely, capitalization has to match as well as all non-letter characters.  However, for our comparison purposes, if the city name is (say) AB and the log entry contains (say) CABD, then the log contains the city, i.e., there doesn’t have to be space or punctuation mark before/after the city name in the log. 
 
The Input: 
 
There will be multiple news scenarios (test cases).  The first line of the input contains a positive integer n, representing the number of news scenarios to filter.  Each scenario follows.  The first line of each test case contains a positive integer, m (1 ≤ m ≤ 50), which represents the number of cities for the test case.  The following m lines contain the names of the cities, one per line.  These names may contain letters, digits, commas, and spaces (assume no leading or trailing spaces).  These input lines (city names) will each be at most 30 characters and will contain at least one non-blank character.  Assume that the words Brett and Favre (in any form of upper/lower case) will not be in any city name.  Also assume that no city name will be a substring of another city name within a test case.  The next input line after the city names will contain another positive integer, k (1 ≤ k ≤ 100), representing the number of log entries for this case.  The next k lines contain one log entry each, given in chronological order (i.e., you don’t need to sort them based 
 15  
on date/time).  The log entries can contain any printable characters but will not exceed 100 characters each.  Assume that a log entry contains at most one city name. 
 
The Output: 
 At the beginning of each test case, output “Brett Log #p:”, on a line by itself, where p is the test case number (starting from 1).  The following lines should simply contain, in order, the lines from the entry log that are significant, according to the given criteria. 
 
Leave a blank line after the output for each test case.  Follow the format illustrated in Sample Output. 
 
Sample Input: 
 2 4 Green Bay Hattiesburg New York Cleveland, Ohio 7 7/23 5:00 PM: Brett leaves Hattiesburg in private plane. 7/23 5:10 PM: Brett eats breakfast omelet on plane. 7/23 5:20 PM: Did I mention Brett is leaving Hattiesburg? 7/23 5:30 PM: Brett falls asleep on plane. 7/23 7:45 PM: Brett lands in Green Bay to waiting fans. 7/23 8:15 PM: Brett watches Packers practice. 7/23 8:20 PM: Deanna is watching practice as well. 2 Cleveland, Ohio New York 5 7/25 10:00 AM: Brett arrives in New York. 7/25 11:00 AM: Brett does press conference in New York. 7/25 1:25 PM: Brett flies to Cleveland, Ohio. 7/25 4:45 PM: Brett does press conference in Cleveland, Ohio. 7/25 6:00 PM: Brett walks onto field in Cleveland, Ohio. 
 Sample Output:  
 Brett Log #1:    7/23 5:00 PM: Brett leaves Hattiesburg in private plane.    7/23 7:45 PM: Brett lands in Green Bay to waiting fans. 
 Brett Log #2:    7/25 10:00 AM: Brett arrives in New York.    7/25 1:25 PM: Brett flies to Cleveland, Ohio. 

 

题意:

给出m个城市,k条日志,如果日志中含有城市表中的一个城市并且不和上一次访问到的城市相同就输出

(我以为是只要访问过就不再访问……)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 55;

string s[N], ss;

int main()
{
    int t, n, m, kcase = 0, pre;
    scanf("%d", &t);
    while(t--)
    {
        pre = -1;
        scanf("%d", &m);
        getchar();
        for(int i = 1; i <= m; ++i)
        {
            getline(cin, s[i]);
        }
        scanf("%d", &n);
        getchar();
        cout<<"Brett Log #"<<++kcase<<":"<<'\n';
        for(int i = 1; i <= n; ++i)
        {
            getline(cin, ss);
            bool flag = 0;
            for(int j = 1; j <= m; ++j)
            {
                if(pre != j && (ss.find(s[j]) != ss.npos))
                {
                    flag = 1;
                    pre = j;
                    break;
                }
            }
            if(flag)
            {
                cout<<"   "<<ss<<'\n';
            }
        }
        cout<<'\n';
    }
    return 0;
}