69,371
社区成员
发帖
与我相关
我的任务
分享
/*基本上差不多了*/
#include <stdio.h>
#include <string.h>
#define MAX 256
int main(void)
{
char s[MAX];
char stk[MAX];
char l[MAX];
int m[MAX];
int n;
int i, j, top, max, pos;
printf("please input the string:\t");
scanf("%s",s);
n = strlen(s);
l[0] = 1;
m[0] = -1;
for (i=1;i<n;i++)
{
max = 0;
pos = -1;
for (j=0;j<i;j++)
if (s[j]<=s[i]&&l[j]>max)
max = l[j], pos = j;
l[i] = max + 1;
m[i] = pos;
}
max = -1;
for (i=0;i<n;i++)
if (l[i]>max)
max=l[i],pos=i;
top = 0;
for (j=0;j<max;j++)
stk[top++] = s[pos], pos = m[pos];
printf("the max is:\t%d\n",max);
while (top--) printf("%c",stk[top]);
printf("\n");
system("pause");
return 0;
}