1071. Speech Patterns (25)
来源:互联网 发布:勇者斗恶龙10国服mac 编辑:程序博客网 时间:2024/06/05 09:33
1.首先是字符串处理,把大写字母的全改为小写字母
2.字符串分隔,遇到不是数字或者字母的字符,就进行分隔
3.使用map来存储次数,最后再存到vector中排序输出
4.需要使用scanf读取字符,不能使用getline
AC代码:
//#include<string>//#include<stack>//#include<unordered_set>//#include <sstream>//#include "func.h"//#include <list>#include <iomanip>#include<unordered_map>#include<set>#include<queue>#include<map>#include<vector>#include <algorithm>#include<stdio.h>#include<iostream>#include<string>#include<memory.h>#include<limits.h>#include<stack>using namespace std;/*Here a "word is defined as a continuous sequence of alphanumerical characters separated by non-alphanumerical characters or the line beginning/end*/bool cmp(const pair<string, int>&a,const pair<string, int>&b){if (a.second > b.second) return true;else if (a.second == b.second && a.first < b.first) return true;else return false;}int main(void){string s="";char c = '1';while (c!='\n'){scanf("%c", &c);s += c;}map<string, int> times;string word = "";for (int i = 0; i < s.size(); i++){if ((s[i] >= 'a'&&s[i] <= 'z') || (s[i] >= 'A'&&s[i] <= 'Z') || (s[i] >= '0'&&s[i] <= '9')){//是字母if ((s[i] >= 'A'&&s[i] <= 'Z'))s[i] = s[i] - 'A' + 'a';word += s[i];}else{//不是字母,则清空wordif (word != "")times[word]++;word = "";}}vector<pair<string, int>> ans(0);for (map<string, int>::iterator ite = times.begin(); ite != times.end(); ite++){ans.push_back( *ite);}sort(ans.begin(), ans.end(), cmp);cout << ans[0].first << " " << ans[0].second << endl;return 0;}
0 0
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- struts+struts注解+jquery
- 网易的评论盖楼设计
- git#gui
- <4>Android HAL层 基础及调用
- A. Two Bases
- 1071. Speech Patterns (25)
- MySQL 常用函数
- MySQL yum安装
- vim更改缩进空格数和TAB键缩进数
- hibernate Restrictions用法
- c# 获取内存信息
- #ifdef #else #endif #fi #ifndef 的用法
- 搜狗输入法/ficix导致Ubuntu下CPU占用高解决方案
- recycleview滑动过程中checkbox控件状态异常