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

     他要从报纸上剪一个个的字母下来,组成一封信,优先考虑大小写相同,再考虑大小写不同。

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstring>
     4 #include<iomanip>
     5 #include<cctype>
     6 #include<string>
     7 #include<cmath>
     8 #include<cstdio>
     9 #include<cstdlib>
    10 #define LL long long
    11 #define PF(x) ((x)*(x))
    12 #define LF(x) ((x)*PF(x))
    13 
    14 using namespace std;
    15 const int INF=1<<31-1;
    16 const int max9=1e9;
    17 const int max6=1e6;
    18 const int max3=1e3;
    19 
    20 int gcd(int a,int b)
    21 {
    22     return b==0?a:gcd(b,a%b);
    23 }
    24 int t1[2][26],t2[2][26];
    25 int main()
    26 {
    27     char s1[220000],s2[220000];
    28     while(cin >> s1 >> s2)
    29     {
    30         int len1=strlen(s1);
    31         int len2=strlen(s2);
    32         memset(t1,0,sizeof(t1));
    33         memset(t2,0,sizeof(t2));
    34         for(int i=0;i<len1;i++)
    35         {
    36             if(s1[i]>='a')
    37                 t1[1][s1[i]-'a']++;
    38             else t1[0][s1[i]-'A']++;
    39         }
    40         for(int i=0;i<len2;i++)
    41         {
    42             if(s2[i]>='a')
    43                 t2[1][s2[i]-'a']++;
    44             else t2[0][s2[i]-'A']++;
    45         }
    46         int Sum1=0;
    47         int Sum2=0;
    48         for(int i=0;i<26;i++)
    49         {
    50             int temp;
    51             temp=min(t1[0][i],t2[0][i]);
    52             Sum1+=temp;
    53             t1[0][i]-=temp;
    54             t2[0][i]-=temp;
    55             temp=min(t1[1][i],t2[1][i]);
    56             Sum1+=temp;
    57             t1[1][i]-=temp;
    58             t2[1][i]-=temp;
    59 
    60             Sum2+=min(t1[0][i],t2[1][i]);
    61             Sum2+=min(t1[1][i],t2[0][i]);
    62         }
    63         cout << Sum1 << " " << Sum2 << endl;
    64     }
    65     return 0;
    66 }
    View Code
  • 相关阅读:
    sql server 报表允许用windows 身份登录的任何人进入
    缩小sql server 日志文件
    IIS Internal Server Error &IIS8中部署WCF服务出错:HTTP 错误 404.3
    less 学习
    访问Index function 两次
    欢迎访问我的个人网站!
    我的web小游戏【持续更新中】
    排序算法(C#)
    存储过程详解
    C#集合
  • 原文地址:https://www.cnblogs.com/I-love-HLD/p/4299369.html
Copyright © 2011-2022 走看看