博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
最大连续递增数字串
阅读量:7182 次
发布时间:2019-06-29

本文共 1447 字,大约阅读时间需要 4 分钟。

题目:求最大连续递增数字串(如“ads3sl456789DF3456ld345AA”中的“456789”。

答:

#include "stdafx.h"#include 
#include
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<<"字符串:"<
<

运行界面如下:

转载地址:http://ipozm.baihongyu.com/

你可能感兴趣的文章
DNS服务的配置与管理(5) 配置转发器
查看>>
零元学Expression Blend 4 - Chapter 44 Flash做的到的Blend也可以!轻松制作拥有动画的MenuBar!(下)...
查看>>
SQL Server定时自动抓取耗时SQL并归档数据脚本分享
查看>>
1.7 中国云应用地图
查看>>
AWK命令和SED命令
查看>>
23种设计模式之外观模式
查看>>
转载:tomcat 与 nginx的区别是什么?
查看>>
重构——改善既有代码的设计
查看>>
WebTreeView
查看>>
在创建内部采购申请进行审批的时候报错,内部申请报错如下:
查看>>
我的友情链接
查看>>
CentOS 7下MySQL服务启动失败的解决思路
查看>>
html中常见又常忽略的问题
查看>>
Ehcache的简单学习3-实际项目使用
查看>>
安装nginx(yum方式)
查看>>
雅虎员工 爆曝更健康:梅耶尔三罪状
查看>>
Android WebView界面自适应
查看>>
ld Memory exhausted一解
查看>>
ora-01031和ORA-01994错误
查看>>
android插件化-apkplugdemo源码阅读指南-10
查看>>