当前位置:编程学习 > C/C++ >>

求最大递增数

要求:求最大递增数
 
如:1231123451
 
输出12345
 
 

#include<stdio.h>  
#include<assert.h>  
void find(char *s)  
{  
    int maxleng = 0;  
    int length = 1;  
    int pos = 0;  
    int i = 0;  
    while(s[i] !='\0')  
    {     
        if((s[i])<'0'||(s[i]>'9'))  
        {  
            assert(0);  
        }  
        if((s[i+1]-'0') > (s[i] -'0'))  
        {  
            length++;  
            i++;  
            continue;  
        }  
        if(length > maxleng)  
        {  
            maxleng = length;  
            pos = i -maxleng;  
            pos++;  
            length = 1;  
            i++;  
            continue;  
        }  
        i++;  
        length = 1;  
    }  
    for(int j =0; j < maxleng; j++)  
    {  
        printf("%c",s[pos++]);  
    }  
}  
int main( )  
{  
    char s[100];  
    scanf("%s",s);  
    find(s);  
    return 0;  
}   

 

 
补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,