
- 字符串筛选
- 字符串截取
- 字符串计数
去重排序
#include <iostream>#include <vector>#include <string>#include <algorithm>using namespace std;int main() {string Input_str;while (cin >> Input_str){vector<string> name_vec;vector<string> name_list;string temp;int num[100] = { 0 };int res_error = 0;for (int i = 0; i < Input_str.size(); i++) {//find the illegal sign if happens change the flagif ((Input_str[i]<'A' || (Input_str[i] > 'Z'&&Input_str[i] < 'a') || Input_str[i]>'z') && Input_str[i] != ',') {res_error = 1;break;}//Use comma as flag to split the stringif (Input_str[i] != ',')temp += Input_str[i];else {name_vec.push_back(temp);temp.clear();}}//deal with the last one without commaname_vec.push_back(temp);//sort the list of namename_list = name_vec;sort(name_list.begin(), name_list.end());name_list.erase(unique(name_list.begin(), name_list.end()), name_list.end());//calculate the number of the namefor (int i = 0; i < name_vec.size(); i++)for (int j = 0; j < name_list.size(); j++)if (name_vec[i] == name_list[j]) {num[j]++;break;}//fine the most oneint max = 0;for (int i = 0; i < 99; i++)if (num[i] > max)max = num[i]; //there is an error in the test//pick the most ticket' ownervector<string> equal_name;for (int i = 0; i < name_list.size(); i++)if (num[i] == max)equal_name.push_back(name_list[i]);//sort againsort(equal_name.begin(), equal_name.end());if (res_error == 1) {cout << "error.0001" << endl;continue;}cout << equal_name[0] << endl;}}
