Loading

【STL】【HDU5842】2016中国大学生程序设计竞赛 - 网络选拔赛 K. Lweb and String (set)(水~~~)

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5842

 

水题,可以用来练习STL中的set

题目大意:给你一串字符串,字符串中的某个字母可以替换为一个数字,求最长上升子序列

例如:  aabcdef --> 1123456   

     acdeaa  --> 123411 

       aabcc    --> 11233

       dacbdda--> 1234112

     红色字体为最长上升子序列

所以我们只需要统计有多少种不同的字母便可以得到答案

代码:(set解法)

 1 #include <set>
 2 #include <cstdio>
 3 #include <iostream>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     set<char> s;
10     int t,ca = 1,cou;
11     char ch[100010];
12     cin >> t;
13     while(t--)
14     {    
15         s.clear();   // 清空
16         cou = 0;   // 初始化
17         scanf("%s",ch);
18         int len = strlen(ch);
19         for(int i = 0;i < len;i++)
20             s.insert(ch[i]);
21         // 迭代器  
22         set<char>::iterator it;
23         for(it = s.begin();it != s.end();it++)
24             cou++;   // 利用迭代器统计set容器中的字符个数
25 
26         printf("Case #%d: %d\n",ca++,cou);
27     }
28     
29     return 0;
30 }

 

posted @ 2018-04-14 22:24  Yiduuannng  阅读(151)  评论(0)    收藏  举报