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 }

 

posted @ 2015-04-12 23:03  Decouple  阅读(249)  评论(0编辑  收藏  举报