zoukankan      html  css  js  c++  java
  • Lweb and String HDU

     
    一水题
     
    Lweb has a string S. 

    Oneday, he decided to transform this string to a new sequence. 

    You need help him determine this transformation to get a sequence which has the longest LIS(Strictly Increasing). 

    You need transform every letter in this string to a new number. 

    A is the set of letters of SS, BB is the set of natural numbers. 

    Every injection f:Acan be treat as an legal transformation. 

    For example, a String “aabc”, A={a,b,c},  and you can transform it to “1 1 2 3”, and the LIS of the new sequence is 3. 

    Now help Lweb, find the longest LIS which you can obtain from SS. 

    LIS: Longest Increasing Subsequence. (https://en.wikipedia.org/wiki/Longest_increasing_subsequence)
     

    Input

    The first line of the input contains the only integer T,(1T20)

    Then T lines follow, the i-th line contains a string S only containing the lowercase letters, the length of SS will not exceed 105.

    Output

    For each test case, output a single line "Case #x: y", where x is the case number, starting from 1. And y is the answer.

    Sample Input

    2
    aabcc
    acdeaa

    Sample Output

    Case #1: 3
    Case #2: 4

    题意:

    咱也不知道这道题什么情况,搞半天是求多少种不同字符



     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 int main()
     5 {
     6     int len, i, t, book[105];
     7     char a[100005];
     8     scanf("%d", &t);
     9     int cas = 0, ans;
    10     while(t--)
    11     {
    12         scanf("%s", a);
    13         ans = 0;
    14         len = strlen(a);
    15         memset(book, 0, sizeof(book));
    16         for(i=0; i<len; i++)
    17         {
    18             if(book[a[i]-'a']==0)
    19             {
    20                 ans++;
    21                 book[a[i]-'a'] = 1;
    22             }
    23         }
    24         printf("Case %d: %d
    ", ++cas, ans);
    25     }
    26     return 0;
    27 }


  • 相关阅读:
    IOS 面试题(不断更新...)
    IOS 数字日期转化为字符串
    C#汉字生成简拼
    ObjectiveC 深浅拷贝
    数组遍历方法forEach 和 map 的区别
    COJ1174(Shining Gems)
    POJ1062(昂贵的聘礼)
    HDOJ1879(继续畅通工程)
    最短路径经典题集(转载)
    HDOJ1863(畅通工程)
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/11370170.html
Copyright © 2011-2022 走看看