求字符串中最长的单词
来源:互联网 发布:学linux 编辑:程序博客网 时间:2024/05/17 06:53
求字符串中最长的单词
描述 :
从一个给定字符串中,查找最长的单词,字符串用空格分隔不同的单词
运行时间限制 : 无限制
内存限制 : 无限制
输入 :
任意字符串,允许输入任意字符,多个单词间已空格分隔,总长度不超过128
输出 :
字符串中最长长度单词
样例输入 :
Hi world
样例输出 :
world
答案提示 :
可能存在多个同样长度的结果,如hello world,结果就是hello world。
多个相同结果间用(1个)空格分隔
struct node{ string x; int y;};void main(){ string a; getline(cin, a); int loc = a.find_first_of(" "); int max = 0; node word[128]; int cnt = 0; while (loc != -1) { word[cnt].x = a.substr(0, loc); word[cnt].y = word[cnt].x.length(); max = max > word[cnt].y ? max : word[cnt].y; cnt++; a = a.substr(loc + 1); loc = a.find_first_of(" "); } word[cnt].x = a.substr(0, loc); word[cnt].y = word[cnt].x.length(); max = max > word[cnt].y ? max : word[cnt].y; cnt++; for (int i = 0; i < cnt; i++) { if (word[i].y == max) { cout << word[i].x << " "; } }}
0 0
- 求字符串中最长的单词
- 编写函数,求给定字符串中最长的单词;
- 一个字符串中求最长单词
- 字符串中最长的单词
- 求句子中最长的单词
- 【C】字符串的输入,求输入字符串中最长的单词
- 将字符串中最长的单词输出
- 查找字符串中单词最长的
- 输出字符串中最长的单词
- Bailian2880 句中最长的单词【字符串】
- 查找字符串中最长的单词
- 一个字符串求最长的单词C++算法
- 求一个字符串中最长的字符串
- 求字符串中单词的个数
- 找到字符串中最长单词
- 分离字符串中单词,并找出最长的
- 查找并输出字符串中最长的单词
- 在一个已知的字符串中找最长单词
- 根据来电号码显示人名
- power(x,n)
- ZOJ 2095和HDU1215(打表)(优化)
- AVPlayer(网络音频资源)的封装
- 2015山东省第六届ACM省赛 Lowest Unique Price
- 求字符串中最长的单词
- Struts2官网翻译
- Win7环境下搭建Android安卓开发环境(原创教程)
- Bug整理——$(window).height()获取到$(document).height()的问题
- linux删除刚刚解压的文件
- ubuntu 14.04 anaconda2安装后caffe编译错误
- SDAU 搜索专题 07 Cable master
- 游戏底层逻辑,MainLoop&&FSM&&MSG(四)
- CSS,font-family:中文字体的英文名称