Content

有 \(n\) 个形如 \(a_i.b_i.c_i.d_i\) 的 IP 地址。有 \(m\) 条命令,每条命令由一条字符串 \(s\) 和一个形如 \(p.q.r.s\) 的 IP 地址,你需要输出这个命令,并输出这个命令所指向的 IP 地址对应的名称。

数据范围:\(1\leqslant n,m\leqslant 1000,0\leqslant a_i,b_i,c_i,d_i,p,q,r,s\leqslant 255,1\leqslant|s|\leqslant 10\)。

Solution

这题乍一看有些高大上,但看到这个数据范围之后,我就认定了这道题目只需要 \(\mathcal{O}(nm)\) 的枚举就能够解决。具体怎么解决?很简单,输入完每一次命令,直接再在所有 \(n\) 个 IP 地址中一个一个去找,看是否有和当前命令的 IP 地址相等的,一旦碰到相等的就直接输出就好了。

Code

string name[1007];
int n, m, a[1007], b[1007], c[1007], d[1007]; int main() {
getint(n), getint(m);
_for(i, 1, n) {cin >> name[i]; scanf("%d.%d.%d.%d", &a[i], &b[i], &c[i], &d[i]);}
_for(i, 1, m) {
string tmpname; int tmpa, tmpb, tmpc, tmpd;
cin >> tmpname;
scanf("%d.%d.%d.%d;", &tmpa, &tmpb, &tmpc, &tmpd);
_for(j, 1, n)
if(tmpa == a[j] && tmpb == b[j] && tmpc == c[j] && tmpd == d[j]) {
cout << tmpname << ' ';
writeint(tmpa), putchar('.');
writeint(tmpb), putchar('.');
writeint(tmpc), putchar('.');
writeint(tmpd), putchar(';'), putchar(' '), putchar('#');
cout << name[j] << endl;
break;
}
}
return 0;
}

CF918B Radio Station 题解的更多相关文章

  1. Radio Station

    B. Radio Station time limit per test:  2 seconds memory limit per test:  256 megabytes input: standa ...

  2. Codeforces Round #459 (Div. 2):B. Radio Station

    B. Radio Station time limit per test2 seconds memory limit per test256 megabytes Problem Dsecription ...

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

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

  4. 【23.48%】【codeforces 723C】Polycarp at the Radio

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. cf723c Polycarp at the Radio

    Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be re ...

  6. codeforces 723C : Polycarp at the Radio

    Description Polycarp is a music editor at the radio station. He received a playlist for tomorrow, th ...

  7. Codeforces 723C. Polycarp at the Radio 模拟

    C. Polycarp at the Radio time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...

  8. Codeforces Round #375 (Div. 2) C. Polycarp at the Radio 贪心

    C. Polycarp at the Radio time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  9. [LeetCode 题解]: Maximum Subarray

    前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Find the c ...

随机推荐

  1. 消息抽象层设计和实现-OSS.DataFlow

    前面已经介绍了消息生产消费中间类库(OSS.DataFlow)的简单使用,这篇主要介绍内部的设计实现.主要内容包含: 1. 消息生产消费的抽象设计. 2. 具体使用示例 一. 消息生产消费的抽象设计. ...

  2. C/C++ Qt ToolBar 菜单组件应用

    ToolBar工具栏在所有窗体应用程序中都广泛被使用,使用ToolBar可以很好的规范菜单功能分类,用户可根据菜单栏来选择不同的功能,Qt中默认自带ToolBar组件,当我们以默认方式创建窗体时,To ...

  3. JDK源码阅读(7):ConcurrentHashMap类阅读笔记

    ConcurrentHashMap public class ConcurrentHashMap<K,V> extends AbstractMap<K,V> implement ...

  4. github文件下载加速器

    https://d.serctl.com/?dl_start

  5. linux下root用户和普通用户切换

    没有root权限干啥都费劲 切换root用户 sudo su 切换普通用户 su player3

  6. Atcoder Grand Contest 030 F - Permutation and Minimum(DP)

    洛谷题面传送门 & Atcoder 题面传送门 12 天以前做的题了,到现在才补/yun 做了一晚上+一早上终于 AC 了,写篇题解纪念一下 首先考虑如果全是 \(-1\)​ 怎么处理.由于我 ...

  7. 【机器学习与R语言】13- 如何提高模型的性能?

    目录 1.调整模型参数来提高性能 1.1 创建简单的调整模型 2.2 定制调整参数 2.使用元学习来提高性能 2.1 集成学习(元学习)概述 2.2 bagging 2.3 boosting 2.4 ...

  8. 39-Remove Duplicates from Sorted Array

    Remove Duplicates from Sorted Array My Submissions QuestionEditorial Solution Total Accepted: 127836 ...

  9. exit(0) exit(1) return() 3个的区别

    exit(0):正常运行程序并退出程序: exit(1):非正常运行导致退出程序: return():返回函数,若在主函数中,则会退出函数并返回一值. 详细说: 1. return返回函数值,是关键字 ...

  10. mysql 索引的注意事项

    mysql 无法使用索引的查询 索引是什么,为什么要用索引,索引使用的时候要注意什么,那些情况下索引无法起作用. 1,索引是什么 mysql的索引也是一张表,并且是一个有序的表,主要记录了需要索引的数 ...