Although this question is a water question, I still prefer it. It is similar to the lexical analysis of compilation principles. The question is to count the words that appear frequently in an article. Use map <string, int> for statistics. In addition, the question should be arranged in Lexicographic Order, but it seems that Map already has this function, so it will not be written. [Cpp] # include <iostream> # include <stdio. h> # include <stdlib. h> # include <string. h> # include <math. h >#include <algorithm> # include <stack> # include <queue> # include <map> using namespace std; int main () {# ifndef ONLINE_JUDGE freopen ("in.txt ", "r", stdin); # endif char word [122]; string a; map <string, int> m; int max = 1; while (scanf ("% s ", word )! = EOF) {. clear (); int flag = 0; for (int I = 0; I <strlen (word); I ++) {if (isalpha (word [I]) | (word [I]> = '0' & word [I] <= '9') {flag = 1; if (word [I]> = 'A' & word [I] <= 'Z') {word [I] + = 32;}. push_back (word [I]);} else if (flag = 1) {if (m. find (a) = m. end () {m. insert (make_pair (a, 1);} else {m [a] ++; if (m [a]> max) {max = m [a];} a. clear (); flag = 0 ;}} if (flag = 1) {if (m. find (a) = m. end ()){ M. insert (make_pair (a, 1);} else {m [a] ++; if (m [a]> max) {max = m [a] ;}}} printf ("% d occurrences \ n", max); for (map <string, int >:: iterator I = m. begin (); I! = M. end (); I ++) {if (I-> second = max) {printf ("% s \ n", I-> first. c_str () ;}} return 0;} similar to the previous question, I used the question code A directly. [Cpp] # include <iostream> # include <stdio. h> # include <stdlib. h> # include <string. h> # include <math. h >#include <algorithm> # include <stack> # include <queue> # include <map> using namespace std; int main () {# ifndef ONLINE_JUDGE freopen ("in.txt ", "r", stdin); # endif char word [122]; string a; map <string, int> m; int max = 1; while (scanf ("% s ", word )! = EOF & strcmp (word ,"#")! = 0) {. clear (); int flag = 0; for (int I = 0; I <strlen (word); I ++) {if (isalpha (word [I]) | (word [I]> = '0' & word [I] <= '9') {flag = 1; if (word [I]> = 'A' & word [I] <= 'Z') {word [I] + = 32;}. push_back (word [I]);} else if (flag = 1) {if (m. find (a) = m. end () {m. insert (make_pair (a, 1);} else {m [a] ++; if (m [a]> max) {max = m [a];} a. clear (); flag = 0 ;}} if (flag = 1) {if (m. find (a) = m. end () {m. Insert (make_pair (a, 1);} else {m [a] ++; if (m [a]> max) {max = m [a] ;}}}www.2cto.com // printf ("% d occurrences \ n", max); for (map <string, int> :: iterator I = m. begin (); I! = M. end (); I ++) {if (I-> second = max) {printf ("% s \ n", I-> first. c_str (); break;} return 0 ;}