zoukankan      html  css  js  c++  java
  • codeforces 518B. Tanya and Postcard 解题报告

    题目链接:http://codeforces.com/problemset/problem/518/B

    题目意思:给出字符串 s 和 t,如果 t 中有跟 s 完全相同的字母,数量等于或者多过 s,就将 s 这个数量加到 YAY! 的答案里,少于的话就加 t 中有的数量;如果 t 中有跟 s 相同的字母但是大小写不对应(例如A-a,z-Z),就加到 WHOOPS 的答案里。

      举个例子就很容易明白了。例如 s 和 t 分别为:

    ncMeXssLHS
    uwyeMcaFatpInZVdEYpwJQSnVxLK

     字符s、n、c、M、e、L、S 两者都有,于是 ans_YAY = 6;XssH中 X 在字符串 t 中 有小写字母x,其他的ssH 在字符串 t 中根本就没有!

       其实...........做virtual 的时候没有看懂题目 = =!是直接看测试数据看出来的。

        If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".

      这句话不仅内有乾坤,还意味深长呢~~~~~看懂题目是很重要滴!

     

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 const int maxn = 2e5 + 5;
     9 const int maxl = 52;
    10 char s[maxn], t[maxn];
    11 int cs[maxl], ct[maxl];
    12 
    13 inline int get_id(char ch)
    14 {
    15     if (ch >= 'a' && ch <= 'z')
    16         return ch - 'a';
    17     return ch-'A' + 26;   // 大写字母从下标26开始
    18 }
    19 int main()
    20 {
    21     #ifndef ONLINE_JUDGE
    22         freopen("in.txt", "r", stdin);
    23     #endif // ONLINE_JUDGE
    24 
    25     while (scanf("%s%s", s, t) != EOF) {
    26         memset(cs, 0, sizeof(cs));
    27         int ls = strlen(s), lt = strlen(t);
    28         for (int i = 0; i < ls; i++)
    29            cs[get_id(s[i])]++;
    30         memset(ct, 0, sizeof(ct));
    31         for (int i = 0; i < lt; i++)
    32            ct[get_id(t[i])]++;
    33 
    34         int ans_YAY = 0;
    35         for (int i = 0; i < maxl; i++) {
    36             int minuend = min(cs[i], ct[i]);
    37             cs[i] -= minuend, ct[i] -= minuend;
    38             ans_YAY += minuend;
    39         }
    40         int ans_WHOOPS = 0;
    41         for (int i = 0; i < 26; i++) {
    42             int added = min(cs[i], ct[i+26]) + min(cs[i+26], ct[i]);
    43             ans_WHOOPS += added;
    44         }
    45         printf("%d %d
    ", ans_YAY, ans_WHOOPS);
    46     }
    47     return 0;
    48 }

       

  • 相关阅读:
    MYSQL5.6学习——mysqldump备份与恢复
    【转】分布式与集群的区别
    (四)伪分布式下jdk1.6+Hadoop1.2.1+HBase0.94+Eclipse下运行wordCount例子
    (三)配置Hadoop1.2.1+eclipse(Juno版)开发环境,并运行WordCount程序
    git pull总是要输入账号和密码
    Undefined index: validate(thinkphp)
    mysql table status
    如何学习web开发环境搭建和脚手架
    serversql tinkphp
    apache 配置
  • 原文地址:https://www.cnblogs.com/windysai/p/4301048.html
Copyright © 2011-2022 走看看