CodeForces 518B. Tanya and Postcard
2 seconds
256 megabytes
standard input
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.
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.
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.
AbC
DCbA
3 0
ABC
abc
0 3
abacaba
AbaCaBA
3 4 这道题目的意思很好理解。
第一种情况,你要的字符串和报纸上的字符串有多少相同的,每个字母相同的个数累加起来再输出。
第二种情况,你要的字符串和报纸上的字符串有多少值相同,但大小写不同,将每个字母的情况累加起来再输出。 在样例里有这样的情况
ZZZzzz
ZZZZzz 答案是:5 1 也就是说,在你统计完第一种情况后,一样的字母需要你减去,然后才能去统计第二种情况。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <ctype.h>
#include <queue>
#define mem(a, b) memset((a), (b), (sizeof(a)))
using namespace std;
const int max_size = + ;
char str1[max_size];
char str2[max_size];
int cnt1[];
int cnt2[]; int main()
{
gets(str1);
gets(str2);
int len1 = strlen(str1);
int len2 = strlen(str2);
mem(cnt1, );
mem(cnt2, ); for(int i = ; i < len1; i++)
{
cnt1[str1[i] - 'A']++;
}
for(int i = ; i < len2; i++)
{
cnt2[str2[i] - 'A']++;
} int ans1, ans2;
ans1 = ans2 = ; for(int i = ; i < ; i++)
{
int ans = min(cnt1[i], cnt2[i]);
cnt1[i] -= ans;
cnt2[i] -= ans;
ans1 += ans;
} for(int i = ; i < ; i++)
{
int ans = min(cnt1[i], cnt2[i+'a'-'A']) + min(cnt2[i], cnt1[i+'a'-'A']);
ans2 += ans;
}
cout << ans1 << " " << ans2 << endl;
return ;
}
CodeForces 518B. Tanya and Postcard的更多相关文章
- codeforces 518B. Tanya and Postcard 解题报告
题目链接:http://codeforces.com/problemset/problem/518/B 题目意思:给出字符串 s 和 t,如果 t 中有跟 s 完全相同的字母,数量等于或者多过 s,就 ...
- CodeForces 518B Tanya and Postcard (题意,水题)
题意:给定两个字符串,然后从第二个中找和第一个相同的,如果大小写相同,那么就是YAY,如果大小写不同,那就是WHOOPS.YAY要尽量多,其次WHOOPS也要尽量多. 析:这个题并不难,难在读题懂题意 ...
- Codeforces Round #293 (Div. 2) B. Tanya and Postcard 水题
B. Tanya and Postcard time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- CF Tanya and Postcard
Tanya and Postcard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CodeForces - 508D Tanya and Password(欧拉通路)
Description While dad was at work, a little girl Tanya decided to play with dad characters. She has ...
- codeforces 659C Tanya and Toys
题目链接:http://codeforces.com/problemset/problem/659/C 题意: n是已经有的数字,m是可用的最大数字和 要求选自己没有的数字,且这些数字的数字和不能超过 ...
- codeforces 659C . Tanya and Toys 二分
题目链接 将给出的已经有了的排序, 在前面加上0, 后面加上1e9+1. 然后对相邻的两项判断. 如果相邻两项之间的数的和小于m, 那么全都选上, m减去相应的值. 如果大于m, 那么二分判断最多能选 ...
- codeforces 508D . Tanya and Password 欧拉通路
题目链接 给你n个长度为3的子串, 这些子串是由一个长度为n+2的串分割得来的, 求原串, 如果给出的不合法, 输出-1. 一个欧拉通路的题, 将子串的前两个字符和后两个字符看成一个点, 比如acb, ...
- Codeforces Round #293 (Div. 2)
A. Vitaly and Strings 题意:两个字符串s,t,是否存在满足:s < r < t 的r字符串 字符转处理:字典序排序 很巧妙的方法,因为s < t,只要找比t字典 ...
随机推荐
- 22章、Java集合框架习题
1.描述Java集合框架.列出接口.便利抽象类和具体类. Java集合框架支持2种容器:(1) 集合(Collection),存储元素集合 (2)图(Map),存储键值对.
- Schema
Schema约束 1.namespace 相当于schema文件的id 2.targetNamespace属性 用来指定schema文件的namespace的值 3.xmlns属性 引入一个约束,它的 ...
- .NET 多个程序配置文件合并到主app.config
.NET 多个程序配置文件合并到主app.config
- NPM
参考资料: 淘宝NPM
- 反射的一些用法(WP8.1下)
我初步的理解:反射就是动态调用(dll)类. 比如某个dll有一个类,通过反射就可以知道它里面属性.方法,就可以实现调用. 确实,dll可以直接引用,但是如果遇到这种情况: 添加.删除功能同属一个Dl ...
- JavaScript闭包(Closure)学习笔记
闭包(closure)是JavaScript语言的一个难点,也是它的特色,很多高级应用都要依靠闭包实现. 下面就是我的学习笔记,对于JavaScript初学者应该是很有用的. 一.变量的作用域 要理解 ...
- PHP常用字符串的操作函数
字符串转换类函数 addcslashes函数:以C语言风格使用反斜线转义字符串中的字符 addslashes函数:使用反斜线引用字符串 chop函数:清除字符串中的连续空格 get_html_tran ...
- 禁用PHP函数,可以对php.ini进行配置
php.ini 里有个 disable_functions 开关选项,此选项可关闭一些危险的函数,比如system,exec 等.比如: disable_functions = phpinfo , 如 ...
- log4Net不能成功生成日志问题(关于配置错误)
log4Net不能成功生成日志问题(关于配置错误) 调试发现问题原因在于 Log4Net IsInfoEnabled 一直为 false,返回的对象中所有 IsXXX 一直为false,这个问题的原 ...
- [转]TextView maxWidth maxLength maxEms 区别
maxWidth=”80dp” 限制TextView最大宽度.必须与layout_width=”wrap_content”搭配使用,当指定layout_width为其他值时,maxWidth会失效. ...