关闭

B. Radio Station

30人阅读 评论(0) 收藏 举报
分类:

As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers.

Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip.

Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him.

Input

The first line of input contains two integers n and m (1 ≤ n, m ≤ 1000).

The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≤ |name| ≤ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct.

The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≤ |command| ≤ 10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers.

Output

Print m lines, the commands in the configuration file after Dustin did his task.

Examples
Input
2 2
main 192.168.0.2
replica 192.168.0.1
block 192.168.0.1;
proxy 192.168.0.2;
Output
block 192.168.0.1; #replica
proxy 192.168.0.2; #main
Input
3 5
google 8.8.8.8
codeforces 212.193.33.27
server 138.197.64.57
redirect 138.197.64.57;
block 8.8.8.8;
cf 212.193.33.27;
unblock 8.8.8.8;
check 138.197.64.57;
Output
redirect 138.197.64.57; #server
block 8.8.8.8; #google
cf 212.193.33.27; #codeforces
unblock 8.8.8.8; #google
check 138.197.64.57; #server

#include<bits/stdc++.h>
using namespace std;
map<string,string>mp;
int main(){
	int n,m;
	string str,ip;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){	
		cin>>str>>ip;
		mp[ip]=str;
	}
	
	for(int i=0;i<m;i++){
		string a,b,c;
		cin>>a>>b;
		int len=b.length();
        c=b.substr(0,len-1);
        cout<<a<<" "<<b<<" #"<<mp[c]<<endl;
	}
	return 0;
} 

0
0
查看评论

codeforces 918 B Radio Station

Description As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin’s task was to add comments t...
  • finalcsdn
  • finalcsdn
  • 2018-01-31 02:38
  • 43

B. Radio Station

time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs the guys fried the radio station facilities, ...
  • jj12345jj198999
  • jj12345jj198999
  • 2018-02-10 21:25
  • 53

POJ-1129 Channel Allocation 解题报告

Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11402   Accepted: 5840...
  • u013009575
  • u013009575
  • 2014-02-13 19:07
  • 515

0.9poj1129(dfs四色问题不错)

http://poj.org/problem?id=1129 Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9779 Accepted: 4983 Descripti...
  • lanjiangzhou
  • lanjiangzhou
  • 2013-05-30 10:56
  • 1212

ZOJ-1084-Channel Allocation(DFS)

  Channel AllocationTime Limit: 1 Second      Memory Limit: 32768 KBWhen a radio station is broadcasting ...
  • lovelyloulou
  • lovelyloulou
  • 2010-03-13 23:53
  • 1641

CodeForces 762E. Radio stations

In the lattice points of the coordinate line there are n radio stations, the i-th of which is described by three integers: xi...
  • wxh010910
  • wxh010910
  • 2017-01-26 22:06
  • 482

codeforces 918 B. Radio Station+AC自动机

http://codeforces.com/contest/918/problem/B B. Radio Station time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...
  • wuxiaowu547
  • wuxiaowu547
  • 2018-01-30 00:31
  • 17

Codeforces Round #459 (Div. 2) B. Radio Station(模拟,字符串)

As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx c...
  • Cutec_lbq
  • Cutec_lbq
  • 2018-01-30 19:44
  • 64

POJ 1129Channel Allocation(四色+dfs搜索剪枝)

Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14797   Accepted: 7526 Descript...
  • jklcl
  • jklcl
  • 2016-11-29 20:12
  • 128

Codeforces 918B Radio Station

B. Radio StationAs the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add com...
  • s540239976
  • s540239976
  • 2018-02-10 16:51
  • 9
    人生哲言
    当能力不足以支持野心时,静下来敲敲代码。
    个人资料
    • 访问:19504次
    • 积分:3241
    • 等级:
    • 排名:第12736名
    • 原创:293篇
    • 转载:15篇
    • 译文:0篇
    • 评论:5条
    博客专栏
    最新评论