国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

1071. Speech Patterns (25)

2019-11-08 02:54:40
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

用map保存Word及次數(shù),由于map自動(dòng)按字典序保存,最后只要輸出第一個(gè)和max一樣的字符就可以了

#include<iostream>#include<string>#include<vector>#include<map>#include<cctype>#include<algorithm>#PRagma warning(disable:4996)using namespace std;int main(){ string str; getline(cin, str); map<string, int> all; string temp; int max = 0; for (auto x : str)//處理字符,并計(jì)算出最大出現(xiàn)次數(shù) { if ((x >= '0'&&x <= '9') ||//對(duì)于0-9,a-z,A-Z的字符增加在當(dāng)前temp末尾(小寫(xiě)) (x >= 'a'&&x <= 'z') || (x >= 'A'&&x <= 'Z')) temp += tolower(x); else if (!temp.empty())//對(duì)于非以上字符,判斷temp是否為空字符,若不為空,保存 { if (++all[temp] > max) max = all[temp]; temp=""; } } if(!temp.empty()) if (++all[temp] > max) max = all[temp];//處理最后剩余的字符 for (auto it = all.begin();it != all.end();it++)//輸出 if (it->second == max) { printf("%s %d/n", it->first.c_str(), it->second);exit(0); }}
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 攀枝花市| 桂林市| 赣榆县| 宁阳县| 荣成市| 灵寿县| 楚雄市| 怀安县| 宁都县| 湖北省| 苍山县| 永定县| 松阳县| 佛山市| 双桥区| 山东省| 河南省| 威远县| 福海县| 乐亭县| 青铜峡市| 张家口市| 顺义区| 凤庆县| 呼伦贝尔市| 桃源县| 翁牛特旗| 蕉岭县| 前郭尔| 土默特左旗| 威远县| 民权县| 邵阳市| 宿州市| 高阳县| 连山| 瑞安市| 澄城县| 缙云县| 温州市| 萨嘎县|