读书人

一路c++小编程题

发布时间: 2013-09-05 16:02:07 作者: rapoo

一道c++小编程题,

string nowWord,beforeWord,result;cin >> nowWord;if(ispunct(nowWord[nowWord.size() - 1]))nowWord = nowWord.substr(0,nowWord.size() - 1);result = beforeWord = nowWord;int count = 1,maxCount = 1;while(cin >> nowWord){if(ispunct(nowWord[nowWord.size() - 1]))nowWord = nowWord.substr(0,nowWord.size() - 1);if (beforeWord == nowWord){count++;}else{beforeWord = nowWord;count = 1;}if(count > maxCount){maxCount = count;result = nowWord;}}if(maxCount == 1) cout << "There is no word repeating." << endl;else cout << "The word of " << result << " repeats: " << maxCount << " times." << endl;return 0;}

特在此分享给大家 参考或给予好的想法参考改进。。谢谢~~

 

读书人网 >编程

热点推荐