本文章由 WyOJ Shojo 从洛谷专栏拉取,原发布时间为 2022-10-24 08:14:30
这是一道模拟题。
先建立 $3$ 个数组:
int c[1210][3];\/\/存储第i每个号码三种的个数
char st[210], name[1210][25];\/\/名字
然后判断这个电话号码应该放在哪里
int type() {
int i, lst = 0;
bool f1, f2;
f1 = f2 = true;
for(i = 1; i < 8; i++) {
if(i % 3 == 2)
continue;
if(st[i] != st[lst])\/\/号码不相等
f1 = false;
if(st[i] >= st[lst])\/\/号码不递减
f2 = false;
lst = i;
}
return f1 + 2 * f2;
}
然后处理读入:
m0 = m1 = m2 = 0;
for(i = 1; i <= n; ++i) {
scanf("%d%s", &nm, name[i]);
while(nm--) {
scanf("%s", st);\/\/读入号码
c[i][type()]++;\/\/把号码对应的类型+1
}
}
然后对于 $c_{i,0},c_{i,1},c_{i,2}$ 取个最大值,然后对于每个数,若他等于对应的最大值,就输出他的名字。
完整代码:
#include <bits\/stdc++.h>
using namespace std;
int c[1145][3];
char st[114], name[1145][25];
int type() {
int i, lst = 0;
bool f1, f2;
f1 = f2 = true;
for(i = 1; i < 8; i++) {
if(i % 3 == 2)
continue;
if(st[i] != st[lst])
f1 = false;
if(st[i] >= st[lst])
f2 = false;
lst = i;
}
return f1 + 2 * f2;
}
int main() {
int n, nm, i, m0, m1, m2;
bool first;
scanf("%d", &n);
m0 = m1 = m2 = 0;
for(i = 1; i <= n; ++i) {
scanf("%d%s", &nm, name[i]);
while(nm--) {
scanf("%s", st);
c[i][type()]++;
}
}
for(i = 1; i <= n; ++i)
m0 = max(m0, c[i][0]);
for(i = 1; i <= n; ++i)
m1 = max(m1, c[i][1]);
for(i = 1; i <= n; ++i)
m2 = max(m2, c[i][2]);
first = true;
printf("If you want to call a taxi, you should call: ");
for(i = 1; i <= n; ++i)
if(c[i][1] == m1) {
if(first)
first = false;
else
printf(", ");
printf("%s", name[i]);
}
printf(".\n");
first = true;
printf("If you want to order a pizza, you should call: ");
for(i = 1; i <= n; ++i)
if(c[i][2] == m2) {
if(first)
first = false;
else
printf(", ");
printf("%s", name[i]);
}
printf(".\n");
first = true;
printf("If you want to go to a cafe with a wonderful girl, you should call: ");
for(i = 1; i <= n; ++i)
if(c[i][0] == m0) {
if(first)
first = false;
else
printf(", ");
printf("%s", name[i]);
}
printf(".\n");
return 0;
}

鲁ICP备2025150228号