【POJ】[2503] Babelfish

Problem Description

Loading...

Problem Analysis

A simple STL application; map + string is enough to get it accepted. When reading the dictionary, you can use c=getchar() to read a character and then check whether it is ‘\n’ to decide when to stop; if it is not, keep reading the rest of the string and then concatenate the pieces.

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<stdio.h>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
char s1[12],s2[12];
int main() {
	map<string,string>q;
	char c;
	while(c=getchar(),c!='\n')	{
		scanf("%s %s",s1,s2);
		getchar();
		string t1=s1;
		s1[0]=c,s1[1]='\0';
		t1=s1+t1;
		string t2=s2;
		q[t2]=t1;
	}
	while(scanf("%s",s1)!=EOF) {
		string res=q[s1];
		if(res.length()>0)
			printf("%s\n",res.c_str());
		else
			printf("eh\n");
	}
	return 0;
}
This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...