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 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.
<center> </center>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.
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, commandonly consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers.
Print m lines, the commands in the configuration file after Dustin did his task.
2 2 main 192.168.0.2 replica 192.168.0.1 block 192.168.0.1; proxy 192.168.0.2;
block 192.168.0.1; #replica proxy 192.168.0.2; #main
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;
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
代码如下:
/* ***********************************************
Author :Boqian Lv
Created Time :2018/1/30 16:13:59
File Name :cf459b.cpp
************************************************ */
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
using namespace std;
struct con
{
string name;
string ip;
}a[1010];
int main()
{
ios::sync_with_stdio(false);
int n,m;
string com,ip0;
cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>a[i].name>>a[i].ip;
}
for(int i=0;i<m;i++)
{
cin>>com>>ip0;
ip0.erase(ip0.end()-1);
//cout<<com<<" "<<ip0<<endl;
for(int j=0;j<1010;j++)
{
if(ip0==a[j].ip)
{
cout<<com<<" "<<ip0<<"; #"<<a[j].name<<endl;
break;
}
}
}
return 0;
}