最大连续递增数字串
2012-09-06 19:39
92 查看
题目:求最大连续递增数字串(如“ads3sl456789DF3456ld345AA”中的“456789”。
答:
运行界面如下:
答:
#include "stdafx.h" #include <iostream> #include <string> using namespace std; //求最大连续递增数字串 string FindMaxIncreNumberSeq(string str) { if ("" == str || str.length() <= 0) { return NULL; } int maxlength = 0; int start = -1; int count = 0; int pos = -1; bool isbegin = true; for (int i = 0; i < str.length(); i++) { if (str[i] >= '0' && str[i] <= '9') { if (isbegin) { pos = i; isbegin = false; count = 1; } else if (str[i] - str[i - 1] == 1) { count++; } else { if (maxlength < count) { maxlength = count; start = pos; } pos = i; count = 1; } if (maxlength < count) { maxlength = count; start = pos; } } else { if (maxlength < count) { maxlength = count; start = pos; } isbegin = true; } } return str.substr(start, maxlength); } int _tmain(int argc, _TCHAR* argv[]) { string str = "23456789ads3sl456789DF012341234567893456ld345AA345678"; cout<<"字符串:"<<str<<endl; cout<<"最大连续递增数字串:"; cout<<FindMaxIncreNumberSeq(str); cout<<endl; return 0; }
运行界面如下:
![](http://pic002.cnblogs.com/images/2012/373143/2012090619362943.jpg)
相关文章推荐
- 微软等数据结构+算法面试100题(15)--求最大连续递增数字串
- 求最大连续递增数字串(如“ads3sl456789DF3456ld345AA”中的“456789”)
- 求最大连续递增数字串
- 求最大连续递增数字串
- 最大连续递增数字串
- 【数据结构】数组中的最大连续递增子序列
- 面试题---求一个串中的最大连续递增数字串
- 微软:求最大连续递增数字串/时钟问题
- [华为机试题]最大连续递增子串
- [HDU] 1087 Super Jumping! Jumping! Jumping! -基本模型中的 最大递增非连续字段和
- 微软100题(87)最大连续递增数字串
- 搜狐笔试 最大连续递增子段和 关键词连续递增
- hdu3308 线段树 求最大连续递增序列
- 严格递增最大连续子段(思维)
- HDU1087 Super Jumping! Jumping! Jumping! DP求非连续单调递增序列的最大和
- 求最大连续递增数字串
- 求最大连续递增数字串
- 最大连续递增子序列
- 任意区间的最长连续递增子序列,最大连续子序列和
- nyoj44 nyoj17 HDU1087 DP动规 连续字符串的和最大值 单调递增最长子序列 单调递增子序列最小个数 非连续最大递增子序列