7-46 新浪微博热门话题 (30分)--map
Posted 2020r
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了7-46 新浪微博热门话题 (30分)--map相关的知识,希望对你有一定的参考价值。
1 #include<iostream> 2 #include <map> 3 #include <string> 4 #include <cstring> 5 using namespace std; 6 map<string, long long int> num;//某话题出现次数 7 int main() 8 { 9 long long int N; 10 cin >> N; 11 cin.get();//吸收回车 12 char ch; 13 char s[150];//临时储存字符串 14 int sp = 0;//sp的指针 15 long long int sum = 0;//还有sum条并列热门话题 16 long long int max = 0;//最热门话题出现次数 17 char hot[150];//存储最热门的话题 18 for (long long int i = 0; i < N; i++) 19 { 20 map<string, bool>flag;//标记字符串是否在本行出现过 21 while ((ch = tolower(cin.get())) != ‘ ‘) 22 { 23 if (ch == ‘#‘) 24 { 25 sp = 0; 26 while ((ch = tolower(cin.get())) != ‘#‘) 27 { 28 if ((ch >= ‘a‘ && ch <= ‘z‘) || (ch >= ‘0‘ && ch <= ‘9‘)) 29 { 30 s[sp++] = ch; 31 } 32 else 33 { 34 if (sp != 0 && (s[sp - 1] >= ‘a‘ && s[sp - 1] <= ‘z‘) || (s[sp - 1] >= ‘0‘ && s[sp - 1] <= ‘9‘)) 35 { 36 s[sp++] = ‘ ‘; 37 } 38 } 39 } 40 if (sp != 0 && s[sp - 1] == ‘ ‘)s[sp - 1] = ‘