Codeforces Round #293 (Div. 2) B. Tanya and Postcard 水题
2015-02-28 14:51
501 查看
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
Output
Input
Output
Input
Output
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
Output
Input
Output
Input
Output
3 4
题意:给你两个串,s和t,如果s中的字符在t中出现过,那么yay++,如果仅仅是大小写不一样的话,那么就w++
找到了,就把那个字符删除掉
解法:优先满足yay,其次再满足w
然后直接跑一发就是了
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
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
题意:给你两个串,s和t,如果s中的字符在t中出现过,那么yay++,如果仅仅是大小写不一样的话,那么就w++
找到了,就把那个字符删除掉
解法:优先满足yay,其次再满足w
然后直接跑一发就是了
int l[30]; int u[30]; string s,t; int main() { cin>>s>>t; for(int i=0;i<t.size();i++) { if('a'<=t[i]&&t[i]<='z') l[t[i]-'a']++; else u[t[i]-'A']++; } int a=0,b=0; for(int i=0;i<s.size();i++) { if(s[i]=='.') continue; if('a'<=s[i]&&s[i]<='z') { if(l[s[i]-'a']>0) { a++; l[s[i]-'a']--; s[i]='.'; } } else { if(u[s[i]-'A']>0) { a++; u[s[i]-'A']--; s[i]='.'; } } } for(int i=0;i<s.size();i++) { if(s[i]=='.') continue; if('a'<=s[i]&&s[i]<='z') { if(u[s[i]-'a']>0) { b++; u[s[i]-'a']--; s[i]='.'; } } else { if(l[s[i]-'A']>0) { b++; l[s[i]-'A']--; s[i]='.'; } } } cout<<a<<" "<<b<<endl; return 0; }
相关文章推荐
- Codeforces Round #293 (Div. 2)——B——Tanya and Postcard
- Codeforces Round #293 (Div. 2) -- B. Tanya and Postcard
- Codeforces Round #293 (Div. 2) B. Tanya and Postcard
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题
- A. GukiZ and Contest-Codeforces Round #307 (Div. 2)-简单水题
- Codeforces Round #288 (Div. 2) D. Tanya and Password
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) B. Code obfuscation 水题
- Codeforces Round #370 (Div. 2) C. Memory and De-Evolution 水题
- Codeforces Round #371 (Div. 2) C. Sonya and Queries 水题
- codeforces水题100道 第五题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas (math)
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
- Codeforces Round #404 (Div. 2) A - Anton and Polyhedrons 水题
- Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题
- Codeforces #261 (Div. 2) A. Pashmak and Garden(水题)
- Codeforces Round #394(Div. 2)A.Dasha and Stairs【水题】
- Codeforces Round #358 (Div. 2) A Alyona and Numbers(水题)
- Codeforces Round #288 (Div. 2)-D. Tanya and Password(欧拉路径及其打印)
- Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool 水题
- Codeforces Round #281 (Div. 2) A. Vasya and Football 暴力水题
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C. Table Tennis Game 2 水题