B. Radio Station

time limit per test2 seconds

memory limit per test256 megabytes

Problem Dsecription

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


解题心得:

  1. 题目说了一大堆其实题意很简单,给你n个ip地址,每个地址有一个对应的名字,然后m次询问,每次询问给你一个ip地址,叫你输出ip地址的名字。当然还有一些乱七八糟的输出要求。
  2. 就是一个hash,将每个地址用一个数表示,然后将地址和这个数存起来,每次询问的时候直接去找这个数,然后将地址输出就行了。主要的是考验一个读题的能力。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+100;
map <string ,string> maps;
string s1;
int n,m,tot=0;
struct NODE
{
string s;
long long num;
}node[10000];
int main()
{
cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>s1;
long long x1,x2,x3,x4,ans =0;
scanf("%lld.%lld.%lld.%lld",&x1,&x2,&x3,&x4);//注意输入的时候控制格式
ans += x1*233;
ans = ans*233+x2;
ans = ans*233+x3;
ans = ans*233+x4;
node[tot].num = ans;
node[tot++].s = s1;
}
for(int i=0;i<m;i++)
{
cin>>s1;
long long x1,x2,x3,x4,ans=0;
scanf("%lld.%lld.%lld.%lld;",&x1,&x2,&x3,&x4);
cout<<s1<<" ";
printf("%lld.%lld.%lld.%lld; #",x1,x2,x3,x4);
ans = x1*233;
ans = ans*233+x2;
ans = ans*233+x3;
ans = ans*233+x4;
for(int i=0;i<tot;i++)
if(node[i].num == ans)
{
cout<<node[i].s<<endl;
break;
}
}
return 0;
}

Codeforces Round #459 (Div. 2):B. Radio Station的更多相关文章

  1. 【Codeforces Round #459 (Div. 2) B】 Radio Station

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用map模拟一下映射就好了. [代码] #include <bits/stdc++.h> using namespace ...

  2. Codeforces Round #459 (Div. 2):D. MADMAX(记忆化搜索+博弈论)

    D. MADMAX time limit per test1 second memory limit per test256 megabytes Problem Description As we a ...

  3. Codeforces Round #459 (Div. 2)

    A. Eleven time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  4. Codeforces Round #482 (Div. 2) : Kuro and GCD and XOR and SUM (寻找最大异或值)

    题目链接:http://codeforces.com/contest/979/problem/D 参考大神博客:https://www.cnblogs.com/kickit/p/9046953.htm ...

  5. Codeforces Round #482 (Div. 2) :B - Treasure Hunt

    题目链接:http://codeforces.com/contest/979/problem/B 解题心得: 这个题题意就是三个人玩游戏,每个人都有一个相同长度的字符串,一共有n轮游戏,每一轮三个人必 ...

  6. Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)

    F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...

  7. Codeforces Round #511 (Div. 2):C. Enlarge GCD(数学)

    C. Enlarge GCD 题目链接:https://codeforces.com/contest/1047/problem/C 题意: 给出n个数,然后你可以移除一些数.现在要求你移除最少的数,让 ...

  8. Codeforces Round #514 (Div. 2):D. Nature Reserve(二分+数学)

    D. Nature Reserve 题目链接:https://codeforces.com/contest/1059/problem/D 题意: 在二维坐标平面上给出n个数的点,现在要求一个圆,能够容 ...

  9. Codeforces Round #459 (Div. 2) D. MADMAX DFS+博弈

    D. MADMAX time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

随机推荐

  1. oop典型应用:实体类

    1. 要知道这个图三者的关系 2.实体类属性类型与数据库类型 3.readonly与const的对比 两者的区别如下: ①const能修饰类中的字段(field)或者局部变量(local variab ...

  2. A light-weight client-side OAuth library for Java

    这个是一个Github上的开源项目-Signpost,主要封装了一些OAuth认证类的方法,项目地址:电极打开 Signpost 什么是Signpost Signpost是一种非常容易.直观的HTTP ...

  3. 移动端,点击a标签链接的pdf报错 Resource interpreted as Document but transferred with MIME type application/pdf

    源码: <a href="11.pdf" class="actcont_a fl report_a" style="display: block ...

  4. iOS 基础笔试题

    参考:https://www.jianshu.com/p/1d3496bc5bda 1.#import 跟#include.@class有什么区别?#import<> 跟 #import& ...

  5. label+input实现按钮开关切换效果

    label+input实现按钮开关切换效果 <!DOCTYPE html> <html lang="en"> <head> <meta c ...

  6. 解决移动端浏览器页面 X轴横向滚动条问题

    写web端页面的时候,总是会出现横向滚动条,即 X 轴滚动条,导致页面左右滑来滑去. 即使设置了 body,html {overflow-x:hidden;width:100%;} 也无法生效. 解决 ...

  7. UVA 340 Master-Mind Hints 猜密码游戏(水)

    题意: 给一串密码(第一行),接着再给你很多行猜测,针对每行猜测,输出两个数字,分表代表:同一列上匹配的个数,不同列上匹配的个数.注:匹配指的是一次,一旦配对,不能再与其他配对. 思路: 每接受一行猜 ...

  8. LeetCode OJ Container With Most Water 容器的最大装水量

    题意:在坐标轴的x轴上的0,1,2,3,4....n处有n+1块木板,长度不一,任两块加上x轴即可构成一个容器,其装水面积为两板的间距与较短板长之积,以vector容器给出一系列值,分别代表在0,1, ...

  9. HDU 2955 Robberies抢劫案(01背包,变形)

    题意:要抢劫,但是抢每个银行都有被抓的概率,问在低于规定的被抓概率情况下最多能抢到多少钱. 输入:第一行为T,表示共T个测试例子.每个例子的第一行给出一个浮点数P,是规定被抓的概率上限.第一行还有一个 ...

  10. bootstrap table保留多选框的分页

    有时候需要完成这种情况: 1.需要设置的是如果第一页点击复选框然后点击其他页面的话,第一页的选项被保存了 2.将所有选择好的复选款的数据保存在数组中 bootstrap table官方文档http:/ ...