• A1071 Speech Patterns [map]


    在这里插入图片描述
    题意:统计由数字和字母组成的“个数”,找出出现频率最高的那个。
    思路:对一个单词一个单词的扫描进map记数

    #include<vector>
    #include<iostream>
    #include<algorithm>
    #include<unordered_map>
    #include<set>
    #include<map>
    #include<cstring>
    #include<string>
    using namespace std;
    bool check(char c)
    {
    	if (c >= '0' && c <= '9')
    		return true;
    	if (c >= 'A' && c < 'Z')
    		return true;
    	if (c >= 'a' && c <= 'z')
    		return true;
    	return false;
    }
    bool cmp(pair<string,int> p1, pair<string,int> p2)
    {
        return p1.second > p2.second;
    }
    int main()
    {
    	map<string, int>count;
    	string str;
    	getline(cin, str);
    	int i = 0;
    	while (i < str.length())
    	{
    		string word;
    		while (i < str.length() && check(str[i]))
    		{
    			if (str[i] >= 'A' && str[i] <= 'Z')
    				str[i] += 32;
    			word += str[i];
    			i++;
    		}
    		if (count.find(word) == count.end())
    			count[word] = 1;
    		else
    			count[word]++;
    		while (i < str.length() && !check(str[i]))
    			i++;
    	}
    	vector<pair<string, int> >vpr;
    	for (map<string, int>::iterator it = count.begin(); it != count.end(); it++)
    	{
    		vpr.push_back(make_pair(it->first, it->second));
    	}
    	sort(vpr.begin(), vpr.end(),cmp);
    	auto it = vpr.begin();
    	cout << it->first << " " << it->second << '
    ';
    }
    
  • 相关阅读:
    systemctl
    防火墙firewalld
    k8s 基础概念
    进程
    模板问题
    自动发现
    oracle操作
    aix 10代oracle zabbix2.4.4 日志监控
    paramiko
    test
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13812033.html
Copyright © 2020-2023  润新知