zoukankan      html  css  js  c++  java
  • CodeForces 518B. Tanya and Postcard

    B. Tanya and Postcard
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.

    The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. 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".

    Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.

    Input

    The first line contains line s (1 ≤ |s| ≤ 2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.

    The second line contains line t (|s| ≤ |t| ≤ 2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.

    Here |a| means the length of the string a.

    Output

    Print two integers separated by a space:

    • the first number is the number of times Tanya shouts "YAY!" while making the message,
    • the second number is the number of times Tanya says "WHOOPS" while making the message.
    Sample test(s)
    Input
    AbC
    DCbA
    Output
    3 0
    Input
    ABC
    abc
    Output
    0 3
    Input
    abacaba
    AbaCaBA
    Output
    3 4

    这道题目的意思很好理解。
    第一种情况,你要的字符串和报纸上的字符串有多少相同的,每个字母相同的个数累加起来再输出。
    第二种情况,你要的字符串和报纸上的字符串有多少值相同,但大小写不同,将每个字母的情况累加起来再输出。

    在样例里有这样的情况
    ZZZzzz
    ZZZZzz

    答案是:5 1

    也就是说,在你统计完第一种情况后,一样的字母需要你减去,然后才能去统计第二种情况。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 #include <ctype.h>
     6 #include <queue>
     7 #define mem(a, b) memset((a), (b), (sizeof(a)))
     8 using namespace std;
     9 const int max_size = 200000 + 10;
    10 char str1[max_size];
    11 char str2[max_size];
    12 int cnt1[60];
    13 int cnt2[60];
    14 
    15 int main()
    16 {
    17     gets(str1);
    18     gets(str2);
    19     int len1 = strlen(str1);
    20     int len2 = strlen(str2);
    21     mem(cnt1, 0);
    22     mem(cnt2, 0);
    23 
    24     for(int i = 0; i < len1; i++)
    25     {
    26         cnt1[str1[i] - 'A']++;
    27     }
    28     for(int i = 0; i < len2; i++)
    29     {
    30         cnt2[str2[i] - 'A']++;
    31     }
    32 
    33     int ans1, ans2;
    34     ans1 = ans2 = 0;
    35 
    36     for(int i = 0; i < 60; i++)
    37     {
    38         int ans = min(cnt1[i], cnt2[i]);
    39         cnt1[i] -= ans;
    40         cnt2[i] -= ans;
    41         ans1 += ans;
    42     }
    43 
    44     for(int i = 0; i < 26; i++)
    45     {
    46         int ans = min(cnt1[i], cnt2[i+'a'-'A']) + min(cnt2[i], cnt1[i+'a'-'A']);
    47         ans2 += ans;
    48     }
    49     cout << ans1 << " " << ans2 << endl;
    50     return 0;
    51 }
    View Code



  • 相关阅读:
    分享一个利用HTML5制作的海浪效果代码
    3人从小公寓创业,到世界最大引擎公司,Unity创始人谈14年...
    决策树--从原理到实现
    使用行为树(Behavior Tree)实现游戏AI
    FSM(状态机)、HFSM(分层状态机)、BT(行为树)的区别
    相遇3000亿美金之巅,阿里腾讯战力与血值几何?
    深入浅出聊Unity3D项目优化:从Draw Calls到GC
    Unity性能优化专题---腾讯牛人分享经验
    高通创始人复盘30年发展历程
    Gym
  • 原文地址:https://www.cnblogs.com/ya-cpp/p/4354483.html
Copyright © 2011-2022 走看看