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;
}