zoukankan      html  css  js  c++  java
  • Radio Station

    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 abc 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, commandonly 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 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 struct node{
     5     char name[15];
     6     int a,b,c,d;
     7 }IP1[1005];
     8 
     9 int main()
    10 {
    11     node IP2[1005];
    12     int x,y,j;
    13     while(~scanf("%d %d",&x,&y))
    14     {
    15         getchar();
    16         for(int i = 0; i < x; i++)
    17         {
    18             scanf("%s %d.%d.%d.%d",&IP1[i].name,&IP1[i].a,&IP1[i].b,&IP1[i].c,&IP1[i].d);
    19             
    20         }
    21         for(int i = 0; i < y; i++)
    22         {
    23             scanf("%s %d.%d.%d.%d;",&IP2[i].name,&IP2[i].a,&IP2[i].b,&IP2[i].c,&IP2[i].d);
    24             for( j = 0; j < x; j++)
    25             {
    26                 if(IP1[j].a != IP2[i].a) continue;
    27                 else if(IP1[j].b != IP2[i].b) continue;
    28                 else if(IP1[j].c != IP2[i].c) continue;
    29                 else if(IP1[j].d != IP2[i].d) continue;
    30                 break;
    31             }
    32             printf("%s %d.%d.%d.%d; #%s
    ",IP2[i].name,IP2[i].a,IP2[i].b,IP2[i].c,IP2[i].d,IP1[j].name);
    33         }
    34     }
    35     return 0;
    36 }
  • 相关阅读:
    root用户Linux 环境变量的配置解决(-bash: jps: command not found)有关问题
    Linux Crontab内环境变量与Shell环境变量的关系及解决问题的办法
    RocketMQ os.sh 系统优化(CentOS)
    Spring Boot修改内置Tomcat端口号
    SpringBoot多跨域请求的支持(JSONP)
    [译]Spring Boot 构建一个RESTful Web服务
    delphi怎样把子窗体显示在pagecontrol的tabsheet
    delphi从TRichEdit获得RTF格式文本(PC版本)
    数据类型表(DELPHI、C++)
    对程序进行注释
  • 原文地址:https://www.cnblogs.com/jj81/p/8384656.html
Copyright © 2011-2022 走看看