微软在线测试之lucky string,有关斐波那契的题目都在此了
2024-10-13 14:27:04
解决方案:
int _tmain(int argc,_TCHAR* argv[])
{
size_t fib[] = {1,2,3,5,8,13,21,34};
string str,tempstr;
cin >> str;
tempstr = str;
auto it = unique(tempstr.begin(),tempstr.end());
tempstr.erase(it,tempstr.end()); // 去重(已假定是有序的,如果无序则先排序) for (auto itstr = str.begin(); itstr != str.end();) // 遍历输入数据
{
string s(itstr,str.end());
for (int i = 0; i < 8;i++)
{
if (fib[i] <= tempstr.size()) // 符合FIB的不同字符有多少,则输出多少次
{
auto singlechar = tempstr[i];
auto findchar = s.find(singlechar);
for (auto itchar = s.begin() + findchar; itchar != s.end()&&*itchar == singlechar;itchar++)
{ // 输出,相同字符连续输出
if (*s.begin() == singlechar) // 每次去掉第一个相同的字符
{
itstr++;
}
cout << string(s.begin(),itchar+1) << endl;
}
}
else
{
tempstr.erase(tempstr.begin()); // 字典输出需要
break;
}
}
} return 0;
}
讨论贴:
http://bbs.csdn.net/topics/391023839
后面碰见有关斐波那契数列的题目非常多,这块还有一个求期望的:
http://bbs.csdn.net/topics/391822110
正确答案:
http://blog.csdn.net/u010476094/article/details/48110405
这他妈的也太难算了吧
最新文章
- CSS3 Animation Cheat Sheet:实用的 CSS3 动画库
- C#程序猿电脑重装记录
- Ezchip Tilera Tile-Mx100: Der 100-ARM-Netzwerkprozessor
- Enum:Backward Digit Sums(POJ 3187)
- Leetcode: Alien Dictionary &;&; Summary: Topological Sort
- Codeforces 626D Jerry&#39;s Protest 「数学组合」「数学概率」
- 如何解决加载动态链接库DLL失败,返回0,GetLastError返回错误码126
- 如何使用 OneAPM 监控微软 Azure Cloud Service ?
- 回顾Ado.Net
- Mysql 冷备份批处理
- POJ_2104_Kth_(主席树)
- bellman_ford寻找平均权值最小的回路
- 老帖收藏,留供参考:SpringMvc2.5+Mybatis3.2.7
- Apache shiro集群实现 (七)分布式集群系统下---cache共享
- springboot之启动原理解析
- 报错【org.springframework.validation.BeanPropertyBindingResult】
- 微信小程序错误码参考大全
- hibernate框架学习第三天:对象状态、一级缓存、快照等
- hibernate的Could not execute JDBC batch update错误原因及处理
- shell脚本--cut命令与awk简单使用