//求最大递增数
#include "stdio.h"
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include<assert.h>
using namespace std;
const int MAX = 20005;
bool check(int length, int maxleng, int i, int pos, char* s)
{
if(length > maxleng)
return true;
if(length == maxleng){
for(int j=0; j<maxleng; j++){
if(s[pos++] > s[i-maxleng+j+1])
return false;
}
}
if(length < maxleng)
return false;
}
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(check(length, maxleng, i, pos, s))
{
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;
}
虽然题目不难,不过细节还是要注意的,提交了11次才用例全过。