2017百度面试现场coding算法一
2017-04-23 17:20
344 查看
求字符串中字符的出现次数,并按照字典序排列
输入:“I am a student a boy”
输出:[(I,1),(a,2),(am,1),(boy,1),(student,1)]
(注意字符串截取的规则,注意最后单词的处理,注意比较函数的引用)
输入:“I am a student a boy”
输出:[(I,1),(a,2),(am,1),(boy,1),(student,1)]
(注意字符串截取的规则,注意最后单词的处理,注意比较函数的引用)
struct Item{ string word; int count; }; bool compare(Item &a,Item &b) { return a.word<b.word; } vector<Item> wordNum(string weight) { vector<Item> vec; int len=weight.length(); int s=0; for(int i=0;i<=len;i++) { if(weight[i]==' '||weight[i]=='\0') { string str=weight.substr(s,i-s); s=i+1; Item temp; int flag=0; for(int j=0;j<vec.size();j++) { if(vec[j].word==str) { vec[j].count++; flag=1; break; } } if(flag==0) { temp.count=1; temp.word=str; vec.push_back(temp); } } } sort(vec.begin(),vec.end(),compare); return vec; }
相关文章推荐
- 2017百度面试现场coding算法二
- 2017百度面试现场coding算法三
- 微软等数据结构+算法面试100题(18)--百度面试题
- 2014------百度面试算法
- 2017百度实习生招聘算法题
- 百度2017校招面试总结
- 百度面试的一道概率方面算法题
- 百度开发测试面试经验2017
- 百度数据挖掘实习工程师一、二现场面试(深圳)
- 面试宝典之二 百度算法面试题分析
- 2017微软面试算法题回顾
- Top 10 Algorithms for Coding Interview 面试十大算法总结
- 解析一道百度面试算法题目
- 百度数据挖掘实习工程师一、二现场面试(深圳)
- 百度面试算法题
- 【面试笔试算法】Problem 1 : DP滑雪问题--网易互联网算法实习生2017笔试题
- 【有趣的面试算法题】之四 求最小不重复数,源于百度2014届校园招聘软件研发岗位深圳站
- 百度2015校园招聘 面试算法题
- 【面试笔试算法】Problem 1 : DP滑雪问题--网易互联网算法实习生2017笔试题
- 测试开发面试真题—算法(百度)