题解 | #单词识别#

单词识别

http://www.nowcoder.com/practice/16f59b169d904f8898d70d81d4a140a0

#include<iostream>
#include<iomanip>
using namespace std;
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<map>
#define MAX 128
int main() {
	ios::sync_with_stdio(false);

	string s;
	getline(cin, s);
	map<string, int>m;
	while (s.size() != 0) {
		int pos = s.find(' ', 0);
		if (pos == s.npos) {
			string temp = s.substr(0, s.size() - 1);
			s.clear();
			transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
			//cout << "temp=" << temp << endl;
			m[temp]++;
		}
		else {
			string temp = s.substr(0, pos);
			s.erase(0, pos + 1);
			transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
			//cout << "temp=" << temp << endl;
			m[temp]++;
		}
		
	}
	

		
		
		
	int lastmax = 1 << 30;
	int max = -1;
	while (max != 0) {
		
		
		auto it = m.begin();
		for (it = m.begin(); it != m.end(); it++) {
			if (max < it->second&&it->second<lastmax)max = it->second;
		}
		for (it = m.begin(); it != m.end(); it++) {
			if (max == it->second) {
				cout << it->first << ":" << it->second << endl;
			}
		}
		max--;
		lastmax = max;
	}
	


	
	return 0;
}
全部评论

相关推荐

01-04 11:28
已编辑
广州华立学院 Java
程序员花海:实习内容写的看起来太偏向于技术了 要结合业务 很多同学搞反了 其实业务才是最重要的 要避免这种单纯罗列技术栈的格式
简历被挂麻了,求建议
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务