国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 普兰县| 平山县| 四子王旗| 青海省| 体育| 岳普湖县| 洛浦县| 饶平县| 上饶县| 泾阳县| 南和县| 陆川县| 定边县| 文水县| 贵溪市| 无棣县| 湘乡市| 治多县| 韩城市| 蒙城县| 双辽市| 呼图壁县| 长寿区| 繁昌县| 台湾省| 巴青县| 景德镇市| 洛隆县| 西贡区| 永泰县| 永昌县| 承德县| 扶余县| 宜宾市| 英吉沙县| 娱乐| 上林县| 福州市| 阳江市| 四平市| 山东省|