B. Tanya and Postcard
2015-03-25 09:48
323 查看
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
output
input
output
input
output
解题说明:此题只需要相同的字母尽可能多。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;
int s[256], t[256];
char tmp[200005];
int main()
{
scanf("%s", tmp);
int len = strlen(tmp);
for(int i = 0; i < len; i++)
{
s[tmp[i]]++;
}
scanf("%s", tmp);
len = strlen(tmp);
for(int i = 0; i < len; i++)
{
t[tmp[i]]++;
}
int a1 = 0, a2 = 0;
for(int i = 'a'; i <= 'z'; i++)
{
int v = min(s[i], t[i]);
a1 += v;
s[i] -= v; t[i] -= v;
v = min(s[i-'a'+'A'], t[i-'a'+'A']);
a1 += v;
s[i-'a'+'A'] -= v; t[i-'a'+'A'] -= v;
a2 += min(s[i], t[i-'a'+'A']);
a2 += min(t[i], s[i-'a'+'A']);
}
printf("%d %d\n", a1, a2);
return 0;
}
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
解题说明:此题只需要相同的字母尽可能多。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;
int s[256], t[256];
char tmp[200005];
int main()
{
scanf("%s", tmp);
int len = strlen(tmp);
for(int i = 0; i < len; i++)
{
s[tmp[i]]++;
}
scanf("%s", tmp);
len = strlen(tmp);
for(int i = 0; i < len; i++)
{
t[tmp[i]]++;
}
int a1 = 0, a2 = 0;
for(int i = 'a'; i <= 'z'; i++)
{
int v = min(s[i], t[i]);
a1 += v;
s[i] -= v; t[i] -= v;
v = min(s[i-'a'+'A'], t[i-'a'+'A']);
a1 += v;
s[i-'a'+'A'] -= v; t[i-'a'+'A'] -= v;
a2 += min(s[i], t[i-'a'+'A']);
a2 += min(t[i], s[i-'a'+'A']);
}
printf("%d %d\n", a1, a2);
return 0;
}
相关文章推荐
- CF Tanya and Postcard
- Codeforces Round #293 (Div. 2) -- B. Tanya and Postcard
- CodeForces 518B. Tanya and Postcard
- Codeforces Round #293 (Div. 2) B. Tanya and Postcard 水题
- CF 518B(Tanya and Postcard-计数统计)
- codeforces 518B. Tanya and Postcard 解题报告
- Codeforces Round #293 (Div. 2) B. Tanya and Postcard
- Codeforces Round #293 (Div. 2)——B——Tanya and Postcard
- 518B - Tanya and Postcard【哎还是string】
- Codeforces Round #346 (Div. 2) C. Tanya and Toys
- Codeforces Round #288 (Div. 2) D Tanya and Password
- Codeforces Round #288 (Div. 2)D.Tanya and Password——欧拉通路
- 【Codeforces Round 324 (Div 2)B】【容斥】Kolya and Tanya 环上n个3元组至少有一组和不为6
- Tanya and Password - CodeForces 508 D 欧拉路径
- Codeforces Round #346 (Div. 2) C.Tanya and Toys
- Codeforces Round #346 (Div. 2)C. Tanya and Toys
- CodeForces 659 C. Tanya and Toys
- Kolya and Tanya
- Codeforces Round #288 (Div. 2) D. Tanya and Password (欧拉通路)
- codeforces 659C C. Tanya and Toys(水题+map)