Codeforces Round #459 (Div. 2) B. Radio Station STL map的使用
2018-02-02 22:54
417 查看
B. Radio Station
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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
output
input
output
题意:首先给出n个服务器名与ip,然后给出m个配置文件与ip,要求按题目要求输出。。。
用map储存即可,map的用法:http://blog.csdn.net/bat603/article/details/1456141
代码如下:
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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
题意:首先给出n个服务器名与ip,然后给出m个配置文件与ip,要求按题目要求输出。。。
用map储存即可,map的用法:http://blog.csdn.net/bat603/article/details/1456141
代码如下:
#include <bits/stdc++.h> using namespace std; map<string,string> sheet; int main() { int n,m; while (~scanf("%d %d",&n,&m)){ string name,ip; for (int i=0;i<n;i++){ cin>>name>>ip; sheet.insert(pair<string,string>(ip,name)); } map<string, string>::iterator iter; for (int i=0;i<m;i++){ cin>>name>>ip; ip.erase(ip.end()-1,ip.end()); //string类的一个函数,删除一个区间内的所有字符(从0开始,左闭右开) cout<<name<<" "<<ip<<"; #"; iter=sheet.find(ip); cout<<iter->second<<endl; } } return 0; }
相关文章推荐
- Codeforces Round #459 (Div. 2) C. The Monster
- 【Codeforces Round 375 (Div 2) C】【语文题】Polycarp at the Radio
- Codeforces Round #459 (Div. 2)总结
- 【Codeforces Round 323 (Div 2)C】【观察找规律 STL map】GCD Table 从GCD矩阵中找出所有原始元素
- Codeforces Round #306 (Div. 2) A. Two Substrings string两个函数使用
- Codeforces Round #459 (Div. 2)-D(dfs暴力)
- Codeforces Round #459 (Div. 2) C.The Monster【贪心&括号匹配】
- Codeforces Round #459 (Div. 2) C-The Monster (贪心)
- Codeforces Round #375 (Div. 2) -- C. Polycarp at the Radio(水题)
- Codeforces Round #375 (Div. 2) Polycarp at the Radio 优先队列模拟题 + 贪心
- Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida's problem(求逆序数对)
- Codeforces Round #459 (Div. 2)C. The Monster
- Codeforces Round #459 (Div. 2)
- Codeforces Round #277.5 (Div. 2) 解题报告
- Codeforces Round #362 (Div. 1) 题解(待续)
- Codeforces Round #319 (Div. 2)
- Codeforces Round #430 (Div. 2) 题解
- Codeforces Round #226 (Div. 2) ABC
- Codeforces Round #400 (Div. 1 + Div. 2, combined) 776E. The Holmes Children(待翻译)
- Codeforces Round #398(Div. 2)D. Cartons of milk【二分+暴力处理】