求最大连续递增数字串
2013-04-02 15:47
323 查看
求最大连续递增数字串(如―ads3sl456789DF3456ld345AA‖中的―456789‖)
#include <iostream> using namespace std; int getSubString(char src[], char rst[]) { /* cout<<rst<<endl; cout<<"the length of the rst is : "<<sizeof(rst)<<endl; rst[2]='\0'; cout<<rst<<endl; cout<<"the length of the rst is : "<<sizeof(rst)<<endl;*/ int pStart = -1, pLen = -1; int cStart = -1; int Index = 0, NIndex = 1; int cnt; while (src[NIndex] != '\0') { cnt = 1; bool isflag = true; while(src[Index] >= '0' && src[Index] <= '9' && src[NIndex] <='9' && src[NIndex] == src[Index] + 1) { if (isflag) { cStart = Index; isflag = false; } NIndex++; Index++; cnt++; } if (cnt > pLen) { pLen = cnt; pStart = cStart; } NIndex++; Index++; } int j = 0; for (int i = pStart; i < pLen+pStart; i++) //之前用for(int i = pStart, j =0; i < pLen+pStart; i++)出现了错误,因为这里相当于重新定义了int j { rst[j++] = src[i]; } rst[j]='\0'; return pLen; } int main() { /* char test[] = "12345"; test[3] = '\0'; cout<<test<<endl;*/ char strSource[]="abs3sl456789DF3456ld345AA"; char strResult[sizeof(strSource)]; cout<<getSubString(strSource, strResult)<<" "<<strResult<<endl; }
相关文章推荐
- 微软:求最大连续递增数字串/时钟问题
- 微软100题(87)最大连续递增数字串
- 面试题---求一个串中的最大连续递增数字串
- 求最大连续递增数字串
- 求一个字符串s的最大连续递增数字子串
- 求最大连续递增数字串
- 求最大连续递增数字串
- 求最大连续递增数字串(如“ads3sl456789DF3456ld345AA”中的“456789”)
- 求最大连续递增数字串(如“ads3sl456789DF3456ld345AA”中的“456789”)
- 求最大连续递增数字串(如“ads3sl456789DF3456ld345AA”中的“456789”)
- 【每日面试题】最大连续递增数字串
- 求一个字符串s的最大连续递增数字子串
- 最大连续递增数字串
- 87 2.求最大连续递增数字串
- 求最大连续递增数字串(如“ads3sl456789DF3456ld345AA”中的“456789”)
- 给定一串数字求连续的最大和
- 找出一串数字中,n个连续的数之和最大c++代码实例及运行结果
- 找出一串数字中,n个连续的数之和最大c++代码实例及运行结果