Lweb and String

来源:互联网 发布:战争机器4淘宝上多少钱 编辑:程序博客网 时间:2024/05/29 21:33

Lweb and String

这里写图片描述
.
.
题意:给一个字符串,字符串中的每一种字母可以转换成任意一种数字,问最终可能的最长严格上升子序列为多长
.
.
解法:就是求字符串有多少个不一样的字母
注意一下先计算出字符长度,不要枚举过程中计算,不然会T
.
.
队友代码

#include <cstdio>#include <cstring>char a[100010];int cnt[30];int main(){    int t, ca = 0;    scanf("%d", &t);    getchar();    while (t--)    {        gets(a);        memset(cnt, 0, sizeof(cnt));        int len = strlen(a);        for (int i = 0; i < len; i++)        {            cnt[a[i] - 'a']++;        }        int ans = 0;        for (int i = 0; i < 26; i++)        {            if (cnt[i] > 0)            {                ans++;            }        }        printf("Case #%d: %d\n", ++ca, ans);    }}
0 0
原创粉丝点击