zoukankan      html  css  js  c++  java
  • 【STL】【HDU5842】2016中国大学生程序设计竞赛

    链接: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
    ",ca++,cou);
    27     }
    28     
    29     return 0;
    30 }
    文章搬运自我的个人博客http://duny31030.top 原博客为静态博客,因备份丢失无法继续更新,所以又搬运回博客园,可能部分文章阅读体验不好,可以到我的静态博客搜索相同标题查看
  • 相关阅读:
    js原生碰撞检测
    基于栈的指令集与基于寄存器的指令集
    偏向锁,轻量级锁
    java 内存模型
    JVM即时编译器
    动态分配
    静态分配
    栈帧笔记
    类加载器
    类加载过程
  • 原文地址:https://www.cnblogs.com/duny31030/p/8836171.html
Copyright © 2011-2022 走看看