H面试程序(29):求最大递增数

要求:求最大递增数

如: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;
}
上一篇:javascript面向对象的程序设计之Object.getOwnPropertyDescriptor()


下一篇:如何使用event 10049分析定位library cache lock and library cache pin