2020.0913组队训练赛。A Alphabet Animals(模拟)

				问题 A: Alphabet Animals



		问题 A: Alphabet Animals
		时间限制: 1 Sec  内存限制: 128 MB

题目描述
You are playing a game in which a group of players take turns saying animal names. The animal name you say when it is your turn must start with the same letter as the previously said animal ends with and it must not have been said previously in this round of the game. If there is no valid name or you cannot come up with one you are eliminated. 
Given the last animal name said before your turn and a list of all names not yet used, can you make it through this turn? If so, can you make sure to eliminate the next player?
输入
The first line of input contains a single word, the animal that the previous player just said. The next line contains a single integer n (0 ≤ n ≤ 105 ), the number of valid unused animal names.
Each of the following n lines contains one valid unused animal name.
All animal names (including the one the previous player said) are unique and consist of at least 1 and at most 20 lower case letters ‘ a ’-‘ z ’.
输出
If there is any animal name you can play that eliminates the next player, output the first such name from the input list, followed by an exclamation mark. Otherwise, if there is any animal name that you can play, output the first such name. Otherwise, output a question mark (in this case you will just have to make up a fake name in the hope that the others will trust you that this is a real animal).
样例输入 Copy
pig
2
goat
toad
样例输出	Copy
goat

日常读题失误QAQ。。。

心不静就好难读题好难写题啊
题意不复述了。
思路:直接模拟。

代码:

#include
using namespace std;
const int N=1e5+1500;
typedef long long ll;
ll sz[N];
map<string,int>mp;
string str[N];
ll vis[N];
int main()
{
     
    string str0,str1;
    cin>>str0;
    mp[str0]=1;
    ll n,cnt=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
     
        cin>>str1;
        if(mp[str1]==1)
            continue;
        mp[str1]=1;
        str[++cnt]=str1;
        sz[cnt]=str1.length()-1;
        vis[int(str1[0]-'a')]++;
    }
    n=cnt;
    char x=str0[str0.length()-1];
    for(int i=1;i<=n;i++)
    {
     
        if(str[i][0]==x)
        {
     
            vis[ int(str[i][0]-'a') ] --;
            if( vis[int(str[i][sz[i]]-'a')]==0 )
            {
     
                cout<<str[i]<<"!"<<endl;
                return 0;
            }
            vis[ int(str[i][0]-'a') ]    ++;
        }
    }
    for(int i=1;i<=n;i++)
    {
     
        if(str[i][0]==x)
        {
     
            cout<<str[i]<<endl;
            return 0;
        }
    }
    cout<<"?"<<endl;
    return 0;
}
 
/**************************************************************
    Problem: 14087
    User: ldu201818
    Language: C++
    Result: 正确
    Time:339 ms
    Memory:22368 kb
****************************************************************/

你可能感兴趣的:(联合训练赛)