zoukankan      html  css  js  c++  java
  • CF Tanya and Postcard

    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

    题目太难懂,三个人读出三种意思。

     1 #include <iostream>
     2 #include <cctype>
     3 #include <cstring>
     4 #include <cstdio>
     5 using    namespace    std;
     6 
     7 int    T_L_HAVE[30] = {0};
     8 int    S_L_HAVE[30] = {0};
     9 int    T_U_HAVE[30] = {0};
    10 int    S_U_HAVE[30] = {0};
    11 
    12 int    main(void)
    13 {
    14     string    s;
    15     string    t;
    16     int    len_s,len_t;
    17     int    sum_yay = 0;
    18     int    sum_whoops = 0;
    19 
    20     cin >> s >> t;
    21     len_s = s.size();
    22     len_t = t.size();
    23 
    24     for(int i = 0;i < len_t;i ++)
    25         if(islower(t[i]))
    26             T_L_HAVE[t[i] - 'a'] ++;
    27         else
    28             T_U_HAVE[t[i] - 'A'] ++;
    29 
    30     for(int i = 0;i < len_s;i ++)
    31         if(islower(s[i]))
    32             S_L_HAVE[s[i] - 'a'] ++;
    33         else
    34             S_U_HAVE[s[i] - 'A'] ++;
    35 
    36 
    37     for(int i = 0;i < len_s;i ++)
    38     {
    39         if(islower(s[i]) && T_L_HAVE[s[i] - 'a'])
    40         {
    41             S_L_HAVE[s[i] - 'a'] --;
    42             T_L_HAVE[s[i] - 'a'] --;
    43             sum_yay ++;
    44         }
    45         else    if(isupper(s[i]) && T_U_HAVE[s[i] - 'A'])
    46         {
    47             S_U_HAVE[s[i] - 'A'] --;
    48             T_U_HAVE[s[i] - 'A'] --;
    49             sum_yay ++;
    50         }
    51     }
    52 
    53     for(int i = 0;i < len_s;i ++)
    54     {
    55         if(islower(s[i]) && S_L_HAVE[s[i] - 'a'] && T_U_HAVE[s[i] - 32 -  'A'])
    56         {
    57             S_L_HAVE[s[i] - 'a'] --;
    58             T_U_HAVE[s[i] - 32 - 'A'] --;
    59             sum_whoops ++;
    60         }
    61         else    if(isupper(s[i]) && S_U_HAVE[s[i] - 'A'] && T_L_HAVE[s[i] + 32 - 'a'])
    62         {
    63             S_U_HAVE[s[i] - 'A'] --;
    64             T_L_HAVE[s[i] + 32 - 'a'] --;
    65             sum_whoops ++;
    66         }
    67     }
    68 
    69 
    70     cout << sum_yay << ' ' << sum_whoops << endl;
    71 
    72     return    0;
    73 }
  • 相关阅读:
    【POJ】1067 取石子游戏(博弈论)
    【POJ】2348 Euclid's Game(扩欧)
    【POJ】1061 青蛙的约会 / 【BZOJ】1477(扩欧)
    【POJ】3090 Visible Lattice Points(欧拉函数)
    【BZOJ】2190 [SDOI2008]仪仗队(欧拉函数)
    【POJ】2115 C Looooops(扩欧)
    【BZOJ】1015 [JSOI2008]星球大战starwar(并查集+离线处理)
    [BZOJ4822][Cqoi2017]老C的任务
    [BZOJ1001][BeiJing2006]狼抓兔子
    [BZOJ1188][HNOI2007]分裂游戏
  • 原文地址:https://www.cnblogs.com/xz816111/p/4420975.html
Copyright © 2011-2022 走看看