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 }

       

  • 相关阅读:
    cs11_c++_lab4a
    cs11_c++_lab3
    cs11_c++_lab2
    cs11_c++_lab1
    Oracle 11.2.4.0 ACTIVE DATAGUARD 单实例安装(COPY创建备库)
    无备份恢复(归档模式)
    rman datafile恢复(归档模式)
    GHOST(幽灵)重大漏洞
    Windows Linux 之间rsync同步CODE文件
    Centos 6.5 SNMP客户端安装及配置版本net-snmp-5.7.3
  • 原文地址:https://www.cnblogs.com/windysai/p/4301048.html
Copyright © 2011-2022 走看看