CF151B Phone Numbers 题解
Content
在一座城市中,每个人的电话号码都是由六位整数组成的,例如 11-45-14。
现在有 \(n\) 个人,第 \(i\) 个人有 \(s_i\) 个人的电话号码。已知:
- 出租车司机的电话号码由六个相同的数字构成(如 66-66-66)。
- 披萨外卖的电话号码由六个递减的数字构成(如 65-43-21)。
- 其他的电话号码都是女生的。
现在给出这 \(n\) 个人所拥有的电话号码。众所周知,找一个拥有某种事情相关的人的电话号码最多的人办这件事总会很靠谱。你需要求出你在办某件事的时候应该找哪些人。
数据范围:\(1\leqslant n\leqslant 100\),\(0\leqslant s_i\leqslant 100\)。
Solution
这题是一道较为简单的模拟题。
我们利用 scanf 的特性,按照格式输入没个电话号码的六个数字,然后按照题目给出的规则将每个电话号码归入题目给出的类型中,同时统计每个人所拥有某种类型的电话号码的数量。
统计完以后,分别按照拥有某种类型的电话号码的数量降序排列,然后找出拥有和最多数量相同的人,最后再按照输入顺序输出即可。
Code
int n, num[107], cnt;
struct node {
string name;
int x[107][7], taxi, pizza, girl, id;
}a[107], ans1[107], ans2[107], ans3[107];
ib cmp1(const node& tmp1, const node& tmp2) {return tmp1.taxi > tmp2.taxi;}
ib cmp2(const node& tmp1, const node& tmp2) {return tmp1.pizza > tmp2.pizza;}
ib cmp3(const node& tmp1, const node& tmp2) {return tmp1.girl > tmp2.girl;}
ib cmpid(const node& tmp1, const node& tmp2) {return tmp1.id < tmp2.id;}
int main() {
n = Rint;
F(i, 1, n) {
num[i] = Rint, a[i].id = i; cin >> a[i].name;
F(j, 1, num[i]) scanf("%1d%1d-%1d%1d-%1d%1d", &a[i].x[j][1], &a[i].x[j][2], &a[i].x[j][3], &a[i].x[j][4], &a[i].x[j][5], &a[i].x[j][6]);
}
F(i, 1, n) {
F(j, 1, num[i]) {
int fl1 = 1, fl2 = 1;
F(k, 1, 6) if(a[i].x[j][k] != a[i].x[j][1]) {fl1 = 0; break;}
F(k, 2, 6) if(a[i].x[j][k] >= a[i].x[j][k - 1]) {fl2 = 0; break;}
if(fl1) a[i].taxi++;
else if(fl2) a[i].pizza++;
else a[i].girl++;
}
}
sort(a + 1, a + n + 1, cmp1);
int tmp = a[1].taxi;
sort(a + 1, a + n + 1, cmpid);
printf("If you want to call a taxi, you should call: ");
F(i, 1, n) if(a[i].taxi == tmp) ans1[++cnt] = a[i];
F(i, 1, cnt) cout << ans1[i].name << (i == cnt ? ".\n" : ", ");
sort(a + 1, a + n + 1, cmp2);
printf("If you want to order a pizza, you should call: ");
tmp = a[1].pizza, cnt = 0;
sort(a + 1, a + n + 1, cmpid);
F(i, 1, n) if(a[i].pizza == tmp) ans2[++cnt] = a[i];
F(i, 1, cnt) cout << ans2[i].name << (i == cnt ? ".\n" : ", ");
sort(a + 1, a + n + 1, cmp3);
printf("If you want to go to a cafe with a wonderful girl, you should call: ");
tmp = a[1].girl, cnt = 0;
sort(a + 1, a + n + 1, cmpid);
F(i, 1, n) if(a[i].girl == tmp) ans3[++cnt] = a[i];
F(i, 1, cnt) cout << ans3[i].name << (i == cnt ? ".\n" : ", ");
return 0;
}
CF151B Phone Numbers 题解的更多相关文章
- CF55D Beautiful numbers 题解
题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...
- Hdoj 1905.Pseudoprime numbers 题解
Problem Description Fermat's theorem states that for any prime number p and for any integer a > 1 ...
- Hdoj 1058.Humble Numbers 题解
Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The ...
- [LeetCode] Add Two Numbers题解
Add Two Numbers: You are given two non-empty linked lists representing two non-negative integers. Th ...
- poj 1995 Raising Modulo Numbers 题解
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6347 Accepted: ...
- CF1265B Beautiful Numbers 题解
Content 给定一个 \(1\sim n\) 的排列,请求出对于 \(1\leqslant m\leqslant n\),是否存在一个区间满足这个区间是一个 \(1\sim m\) 的排列. 数据 ...
- CF1157A-Reachable Numbers题解
原题地址 题目大意:有一个函数\(f(x)\),效果是将\(x+1\)后,去掉末尾所有的\(0\),例如: \(f(599)=6\),因为\(599+1=600→60→6\) \(f(7)=8\),因 ...
- CF359D:Pair of Numbers——题解
https://vjudge.net/problem/CodeForces-359D http://codeforces.com/problemset/problem/359/D 题目大意: 给一串数 ...
- Timus : 1002. Phone Numbers 题解
把电话号码转换成为词典中能够记忆的的单词的组合,找到最短的组合. 我这道题应用到的知识点: 1 Trie数据结构 2 map的应用 3 动态规划法Word Break的知识 4 递归剪枝法 思路: 1 ...
随机推荐
- Python学习手册——第二部分 类型和运算(1)之字符串
Python全景 1.程序由模块构成. 2.模块包含语句. 3.语句包含表达式. 4.表达式建立并处理对象. 在python中数据是以对象的形式出现的!!! 为什么使用内置类型 内置对象使程序更容易编 ...
- 9.1 k8s pod版本更新流程及命令行实现升级与回滚
1.创建 Deployment root@k8-deploy:~/k8s-yaml/controllers/deployments# vim nginx-deployment.yaml apiVers ...
- 华为云企业级Redis评测第一期:稳定性与扩容表现
摘要:采用Redis Labs推出的多线程压测工具memtier_benchmark对比测试下GaussDB(for Redis) 和原生Redis的特性差异. 本文分享自华为云社区<华为云企业 ...
- Linux终端使用aplay播放wav
Linux终端使用aplay播放wav aplay是一个ALSA的声卡命令行soundfile录音机的驱动程序. 在linux下可以使用下面命令来查看用法: man aplay 所以可以使用来播放.w ...
- 如何使用scp在Linux服务器的后台传输文件?
目录 一.上传 常规操作 建议 后台运行 二.下载 两台服务器间文件如何传输?对于小文件,可以先从Linux服务器传到window,再传到另一台服务器.对于大的文件,如测序数据.比对文件等.这样的方法 ...
- NECAT组装ONT long reads
NECAT 可用于ONT数据的纠错,组装,如果想对ONT long reads进行call SV,也可以使用necatsv. githup网址:https://github.com/xiaochuan ...
- R语言中的read.table()
参考资料:http://www.cnblogs.com/xianghang123/archive/2012/06/06/2538274.html read.table(file, header = F ...
- mysql-日期时间函数大全
DAYOFWEEK(date) 返回日期date是星期几(1=星期天,2=星期一,--7=星期六,ODBC标准)mysql> select DAYOFWEEK('1998-02-03'); ...
- C语言中内存对齐与结构体
结构体 结构体是一种新的数据类型,对C语言的数据类型进行了极大的扩充. struct STU{ int age; char name[15]; }; struct STU a; //结构体实例 str ...
- 学习java 7.25
学习内容: 特殊边框 1. TitledBorder:它的作用并不是直接为其他组件添加边框,而是为其他边框设置标题,创建该类的对象时,需要传入一个其他的Border对象; 2. CompoundBor ...