【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 }

用map也可以解决这道问题,希望大家可以在用set解决以后尝试用map解决

代码我就不写了

set、map的相关知识都可以在别人的博客中找到,我就不贴出来了

原文地址:https://www.cnblogs.com/duny31030/p/8836171.html

时间: 2024-08-28 23:02:05

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

2016中国大学生程序设计竞赛 - 网络选拔赛 1011 Lweb and String

题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1011&cid=719 Sample Input 2 aabcc acdeaa Sample Output Case #1: 3 Case #2: 4 *************************************************** 题意:我只能说题意神马都是浮云,纯属干扰,直接看代码吧 1 #include<stdio.h> 2 #i

2016中国大学生程序设计竞赛 - 网络选拔赛

solved 4/11 2016中国大学生程序设计竞赛 - 网络选拔赛

HDU 5833 Zhu and 772002(高斯消元)——2016中国大学生程序设计竞赛 - 网络选拔赛

传送门 Zhu and 772002 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 48    Accepted Submission(s): 16 Problem Description Zhu and 772002 are both good at math. One day, Zhu wants to test the abili

HDU 5832 A water problem(取模~)—— 2016中国大学生程序设计竞赛 - 网络选拔赛

传送门 A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 60    Accepted Submission(s): 37 Problem Description Two planets named Haha and Xixi in the universe and they were created wit

2016中国大学生程序设计竞赛 - 网络选拔赛 C. Magic boy Bi Luo with his excited tree

Magic boy Bi Luo with his excited tree Problem Description Bi Luo is a magic boy, he also has a migic tree, the tree has N nodes , in each node , there is a treasure, it's value is V[i], and for each edge, there is a cost C[i], which means every time

2016中国大学生程序设计竞赛 - 网络选拔赛 1004 Danganronpa

Problem Description Chisa Yukizome works as a teacher in the school. She prepares many gifts, which consist of n kinds with a[i] quantities of each kind, for her students and wants to hold a class meeting. Because of the busy work, she gives her gift

【数论】2016中国大学生程序设计竞赛 - 网络选拔赛 A. A water problem (大整数取模)

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5832 题意:两个星球,一个星球一年只有137天,一个星球一年只有73天 输入N(爆炸后第N天),判断这是否为这两个星球的第一天 只要这个数是137与73的公倍数就好了(0比较特殊) 坑点:N的长度不超过10000000 只能用字符串来存储 大整数整除:紫书P314 大整数整除:首先把大整数写成"自左向右"的形式:1234 = (((1*10)+2)*10+3)*10+4 然后每步取模 代码 1

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha&#39;s staff 思维

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 题意:在笛卡尔坐标系下,画一个面积至少为  n 的简单多边形,每次只能画一条边或者一个格子的对角线,问至少要画几条. 解法:如果一个斜着的矩形长宽分别是 a,b,那么它的面积是 2ab.最优解肯定是离 sqrt(n/2)很近的位置.想想 n=5 时答案为什么是7 然后在那个小范围内枚举一下就好了.我给一张做题时画的图 #include <bits/stdc++.h> using namesp

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha&#39;s staff(几何找规律)

Problem Description "You shall not pass!"After shouted out that,the Force Staff appered in CaoHaha's hand.As we all know,the Force Staff is a staff with infinity power.If you can use it skillful,it may help you to do whatever you want.But now,hi