コード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
char to_num(char c){
return c-'0';
}
void get_num(string s, char* c){
c[0] = to_num(s[0]);
c[1] = to_num(s[1]);
c[2] = to_num(s[3]);
c[3] = to_num(s[4]);
c[4] = to_num(s[6]);
c[5] = to_num(s[7]);
}
bool taxi(char* c){
return
(c[0]==c[1]) &&
(c[1]==c[2]) &&
(c[2]==c[3]) &&
(c[3]==c[4]) &&
(c[4]==c[5]);
}
bool pizza(char* c){
return
(c[0]>c[1]) &&
(c[1]>c[2]) &&
(c[2]>c[3]) &&
(c[3]>c[4]) &&
(c[4]>c[5]);
}
void output(vector<string> v){
for(int i = 0; i < v.size()-1; i++){
cout << v[i] << ", ";
}
cout << v.back() << "." << endl;
}
int main(int argc, char *argv[]){
int n;
cin >> n;
vector<string> names(n);
vector<int> n_taxi(n, 0), n_pizza(n, 0), n_girl(n, 0);
string phone;
char buf[100];
for(int i = 0; i < n; i++){
int s;
cin >> s >> names[i];
for(int j = 0; j < s; j++){
cin >> phone;
get_num(phone, buf);
if(taxi(buf)) n_taxi[i]++;
else if(pizza(buf)) n_pizza[i]++;
else n_girl[i]++;
}
}
int m_taxi, m_pizza, m_girl;
m_taxi = *max_element(n_taxi.begin(), n_taxi.end());
m_pizza = *max_element(n_pizza.begin(), n_pizza.end());
m_girl = *max_element(n_girl.begin(), n_girl.end());
vector<string> f_taxi, f_pizza, f_girl;
for(int i = 0; i < n; i++){
if(n_taxi[i] == m_taxi) f_taxi.push_back(names[i]);
if(n_pizza[i] == m_pizza) f_pizza.push_back(names[i]);
if(n_girl[i] == m_girl) f_girl.push_back(names[i]);
}
cout << "If you want to call a taxi, you should call: ";
output(f_taxi);
cout << "If you want to order a pizza, you should call: ";
output(f_pizza);
cout << "If you want to go to a cafe with a wonderful girl, you should call: ";
output(f_girl);
return 0;
}