解题思路:
注意事项:
参考代码:
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <algorithm> #include <string> #include <vector> #include <map> #include <stdio.h> using namespace std; map< int, string > m; void getMaxWordLen(string sentence) { int offset = 0; int it1 = 0, it2 = 0; int wordLen = 0; string word; while (true) { it2 = sentence.find(' ', offset); if (it2 == string::npos) { word = sentence.substr(it1, sentence.size() - it1); wordLen = word.length(); if (m.find(wordLen) == m.end()) m[wordLen] = word; break; } word = sentence.substr(it1, it2 - it1); wordLen = word.length(); if (m.find(wordLen) == m.end()) { m[wordLen] = word; } offset = it2 + 1; it1 = it2 + 1; } } int main() { freopen("input5.txt","r",stdin); string s; getline(cin, s); getMaxWordLen(s); cout << (--m.end())->second << endl; fclose(stdin); return 0; }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.1 (Java代码)浏览:781 |
【计算两点间的距离】 (C语言代码)浏览:883 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:575 |
哥德巴赫曾猜测 (C语言代码)浏览:2345 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:690 |
1124题解浏览:595 |
Tom数 (C语言代码)浏览:725 |
剪刀石头布 (C语言代码)浏览:1436 |
图形输出 (C语言代码)浏览:944 |
整除问题 (C语言代码)浏览:526 |