1 #include <cstdio>
 2 #include <cstring>
 3 using namespace std;
 4 
 5 char str[10010];
 6 int ans[10010];
 7 
 8 int main()
 9 {
10     int i,j,k;
11     int T;
12     scanf("%d%*c",&T);
13     while(T--)
14     {
15         memset(str,0,sizeof(str));
16         memset(ans,0,sizeof(ans));
17 
18         scanf("%s",str);
19         int res = 1;//初始化为1就AC
20         ans[0] = 1;
21         for(i=1; str[i]!='\0'; i++)
22         {
23             ans[i] = 1;//重要
24             int max = 0;//定义在里面
25 
26             //for(j=0; j<i; j++)
27            /// if(str[j]<str[i]&&ans[j]>max)
28             //    max = ans[j];
29             //max必须初始化为0,否则如果内层for一次也不执行的话就错了
30           //  ans[i] = max + 1;
31 
32             
33             for(j=0; j<i; j++)
34             if(str[j]<str[i]&&ans[i]<ans[j]+1)
35                 ans[i] = ans[j]+1;
36             if(res<ans[i])
37                 res =ans[i];
38         }
39        printf("%d\n",res);
40     }
41     return 0;
42 }

 

相关文章:

  • 2021-06-01
  • 2022-12-23
  • 2021-11-21
  • 2021-08-05
  • 2022-12-23
猜你喜欢
  • 2021-12-06
  • 2021-12-17
  • 2022-02-20
  • 2021-08-12
  • 2022-12-23
  • 2021-04-20
  • 2022-01-22
相关资源
相似解决方案