Microsoft 2013 Programming Beauty Messenger Game _map

Source: Internet
Author: User
Tags strtok tidy
#include <iostream>
#include <map>
#include <string>
#include <cstring>
# Include<cstdio>
using namespace std;
int main ()
{
	int T, k = 1;
	scanf_s ("%d", &t);
	while (t--)
	{
		int n, m;
		string s1, S2;
		CIN >> n >> m;
		Map<string, string> Mymap;
		for (int i = 0; i<m; i++)
		{
			cin >> s1 >> S2;
			if (!mymap.count (S1))
				mymap[s1] = s2;
		}
		char *p;
		String ans (""), str ("");
		GetChar ();
		Getline (cin, ans);
		for (int i = 1; i<n; i++)
		{
			str = ans;
			ans = "";
			p = strtok (Const_cast<char *> (Str.c_str ()), "");
			while (P!= NULL)
			{
				ans = "";
				if (!mymap.count (p))
					ans + = p;
				else
					ans + + mymap[p];
				Get Next token:
				p = strtok (NULL, "");
			}
		}
		printf ("Case #%d:", k++);
		cout << ans << endl;
	return 0;
}

Describe

Alice and Bob and several other good friends are playing the message game together. The game goes like this: First, all the players are in a row in order, Alice stands first, and Bob stands last. Then Alice would like to whisper a word to the second player, the second player quietly told the third, and the third told fourth place ... And so on, until the penultimate digit tells Bob. Two players in the message, can not let others hear, and can not use the body action to explain. Finally, Bob told everyone what he had heard, and Alice told everyone what she had thought.

As there may be some bias in the messenger process, the more players there are, the more likely Bob will be to hear the last words than Alice would have thought. What Bob hears often turns into something very funny, so everyone has fun. After several rounds of games, Alice noticed that in the two-person message, some words often mistakenly become other specific words. Alice has collected such a list of lexical transformations, and she wants to know what her words will look like when it reaches Bob, and ask you to write a program to help her. Input

Input includes multiple sets of data. The first line is an integer T that indicates how many sets of test data are available. The first row of each set of data consists of two integers N and M, representing the number of players and the length of the word conversion list, respectively. Then there is the M line, each containing two words A and b separated by a space, which means that word a must become B in the messenger. Enter data to guarantee no duplicates of a. The last line contains several words separated by a single space, representing the sentences Alice wants, with a total length of no more than 100 characters. All words contain only lowercase letters and are no more than 20 in length, and different tenses of the same word are considered to be different words. You can assume that words that are not in the list will never change. Output

For each set of test data, output a single line of "Case #c: S". Where c is the test data number, S is the sentence that Bob hears. The format of S is the same as that of Alice in the input data. Data range

1≤t≤100

Small data: 2≤n≤10, 0≤m≤10

Big data: 2≤n≤100, 0≤m≤100

Sample input

2
4 3 ship
sheep
sinking thinking
thinking sinking the ship is
sinking
ten 5
tidy tiny
Tiger Liar
tired tire
tire Bear
Liar Bear
A tidy tiger is tired
Sample output
Case #1: The sheep was thinking case
#2: A tiny-bear are bear

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.