# 输出最长的递增数字字符串

<p>如何在一亿位整数组成的字符串中找到最长的递增数字字符串&#xff1f;</p>

以下程序实现了这一功能，请你填补空白处内容：

```cpp
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 100000
int main()
{
    char buf[MAX_SIZE] = {0};
    int i = 0, len = 0, index = 0;
    char maxbuf[12] = {0};
    char maxbuf2[12] = {0};
    int maxlen = 0;
    gets(buf);
    len = strlen(buf);
    maxbuf2[0] = buf[0];
    i = 1;
    index = 1;
    while (i < len)
    {
        if (buf[i] > buf[i - 1])
        {
            maxbuf2[index] = buf[i];
            index++;
        }
        else
        {
            _________________;
        }
        i++;
    }
    if (index > maxlen)
    {
        maxlen = index;
        strcpy(maxbuf, maxbuf2);
        maxbuf[index] = '\0';
    }
    printf("最大串长度:%d,字符串:%s\n", maxlen, maxbuf);
    return 0;
}
```

## template

```cpp
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 100000
int main()
{
    char buf[MAX_SIZE] = {0};
    int i = 0, len = 0, index = 0;
    char maxbuf[12] = {0};
    char maxbuf2[12] = {0};
    int maxlen = 0;
    gets(buf);
    len = strlen(buf);
    maxbuf2[0] = buf[0];
    i = 1;
    index = 1;
    while (i < len)
    {
        if (buf[i] > buf[i - 1])
        {
            maxbuf2[index] = buf[i];
            index++;
        }
        else
        {
            if (index > maxlen)
            {
                maxlen = index;
                strcpy(maxbuf, maxbuf2);
                maxbuf[index] = '\0';
                maxbuf2[0] = buf[i];
                index = 1;
            }
            else
            {
                maxbuf2[0] = buf[i];
                index = 1;
            }
        }
        i++;
    }
    if (index > maxlen)
    {
        maxlen = index;
        strcpy(maxbuf, maxbuf2);
        maxbuf[index] = '\0';
    }
    printf("最大串长度:%d,字符串:%s\n", maxlen, maxbuf);
    return 0;
}
```

## 答案

```cpp
if (index > maxlen)
{
	maxlen = index;
	strcpy(maxbuf, maxbuf2);
	maxbuf[index] = '\0';
	maxbuf2[0] = buf[i];
	index = 1;
}
else
{
	maxbuf2[0] = buf[i];
	index = 1;
}
```

## 选项

### A

```cpp
if (index > maxlen)
{
	maxlen = index;
	strcpy(maxbuf, maxbuf2);
	maxbuf[index] = '\0';
	maxbuf2[0] = buf[i];
	index = 1;
}
```

### B

```cpp
if (index > maxlen)
{
	maxlen = index;
	strcpy(maxbuf, maxbuf2);
	maxbuf[index] = '\0';
	maxbuf2[0] = buf[i];
	index++;
}
else
{
	maxbuf2[0] = buf[i];
	index++;
}
```

### C

```cpp
if (index > maxlen)
{
	maxlen = index;
	strcpy(maxbuf, maxbuf2);
	maxbuf[index] = '\0';
	maxbuf2[0] = buf[i];
	index = 0;
}
else
{
	maxbuf2[0] = buf[i];
	index = 0;
}
```