LONGEST WORD 解题思路 codeEval
来源:互联网 发布:mac如何显示包内容 编辑:程序博客网 时间:2024/06/01 16:41
这一题跟PENULTIMATE WORD是一样的,首先拆词出来,然后找到最长的那个单词输出即可
#include <iostream>#include <fstream>#include <vector>#include <string>using namespace std;void split(const string& s, const string& delim, vector<string> &v) {if(s.size() == 0) return;int last = 0;size_t index = s.find_first_of(delim, last);while(index != string::npos) {v.push_back(s.substr(last, index-last));last = index+1;index = s.find_first_of(delim, last);}if(index - last > 0)v.push_back(s.substr(last, index-last));}int main (int argc, char* argv[]) {ifstream file;string lineBuffer;file.open(argv[1]);while (!file.eof()) {getline(file, lineBuffer);if (lineBuffer.length() == 0)continue; //ignore all empty lineselse {vector<string> v;unsigned int maxIndex = 0, maxLen = 0;split(lineBuffer, " ", v);for(int i=0; i<(int)v.size(); i++) {if(v[i].length() > maxLen) {maxIndex = i;maxLen = v[i].length();}}cout << v[maxIndex] << endl;}}return 0;}
0 0
- LONGEST WORD 解题思路 codeEval
- PENULTIMATE WORD解题思路 codeEval
- UVA 12543 Longest Word 解题报告
- leetCode 5.Longest Palindromic Substring 解题思路与方法
- LeetCode —— 14. Longest Common Prefix解题思路
- 【LeetCode】Longest Word in Dictionary through Deleting 解题报告
- [Leetcode] 524. Longest Word in Dictionary through Deleting 解题报告
- LeetCode OJ:Word Ladder II 解题思路过程详谈
- 解题思路
- 解题思路
- 解题思路
- 解题思路
- 解题思路
- leetCode 14.Longest Common Prefix(最长公共前缀) 解题思路和方法
- leetCode 32.Longest Valid Parentheses (有效的最大括号) 解题思路和方法
- leetCode 58.Length of Last Word (最后单词的长度) 解题思路和方法
- leetCode 79.Word Search (词搜索) 解题思路和方法
- 话说解题思路
- Power BI的一些视频演示资源
- Qt 实现桌面雪花飘落 - 修改1
- IOS图片压缩和扩展
- C# 2008 windows mobile 6调试环境
- PENULTIMATE WORD解题思路 codeEval
- LONGEST WORD 解题思路 codeEval
- FWNX-C++ version - power
- !!!Obj-c on Mac --- Chapter 10 - 12 Initialization Property Category
- DP16 Floyd Warshall Algorithm @geeksforgeeks
- djang框架学习中遇到的问题总结
- 活期储蓄账目管理系统(C++课程设计)
- 复数计算器
- FWNX- about the abs function -
- DP17 最少回文切割次数 Palindrome Partitioning @geeksforgeeks