华为oj 在字符串中找出连续最长的数字串
2015-11-25 21:06
465 查看
#include<iostream> #include<string.h> #define N 1000 using namespace std; void continueMax(char *p) { if(!strlen(p)) { cout<<"0"<<endl; } else { int max = 0; char *q = p; bool flag = false; int count = 0; char *temp = p; while(*p != '\0') { if(isdigit(*p)&&flag) //进入连续数字计数阶段 { ++count; } else if(!isdigit(*p)&&flag) //已经离开连续数字区域 { flag = false; if(max<count) { max = count; q = temp; } count = 0; } else if(isdigit(*p)&& !flag) //开始进入连续数字计数阶段 { flag = true; temp = p; if(!count) ++count; } //还未遇到连续数字 //cout<<"now:"<<*p<<" "<<flag<<"count:"<<count<<"max:"<<max<<"temp"<<*temp<<endl; ++p; } if(count>max) { max = count; q = temp; } if(!max) { cout<<"0"<<endl; } else { int i = 0; for(;i<max;i++) { if(*q != '\0') { cout<<*q; q++; } } cout<<","<<max<<endl; } } } int main() { char a ; gets(a); continueMax(a); return 0; }
相关文章推荐
- hdoj 骨牌铺方格
- QT多重继承的时候,要把QObject放在最前面,否则报错——C++认为人性本恶,默认都是私有的,这点和Delphi的世界观不一样
- c++ 缺少动态库
- 数据结构——建立单向链表(java实现)
- 用win7(64位)远程桌面连接linux(Ubuntu14.04)详细教程
- OpenGL三维图形编程技术【转】
- Spring源码阅读——序言
- Python 编码踩坑小记
- 6个可以隐藏运行bat,浏览器等程序的方法
- 转一贴,今天实在写累了,也看累了--【Python异步非阻塞IO多路复用Select/Poll/Epoll使用】
- 文件描述符和文件指针的区别
- POJ - 2195 Going Home(最小费用最大流)
- Ionic-wechat项目边开发边学(三):自定义样式,指令,服务
- 96 Unique Binary Search Trees
- 118 stackoverflow高票系列 -- sql注入
- 微信公众号支付接口文档最新版下载
- 类找不到异常 Caused by: java.lang.NoClassDefFoundError
- 数组(交OR并)
- 黑马程序员——Foundation框架——NSArray和NSMutableArray的介绍及使用
- CodeForces 545C Woodcutters (贪心)