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字典 ...
随机推荐
- Win7如何删除需要管理员权限才能删除的文件夹
在Windows 7系统运行中.往往会遇到想要删除某个文件夹时,系统提示:文件夹访问被拒绝 你需要权限来执行此操作,如何才能删除此类文件夹呢? ------------------ --------- ...
- AE开发实现GP工具IDW
IDW——空间插值 IDW(Inverse Distance Weighted)是一种常用而简便的空间插值方法,它以插值点与样本点间的距离为权重进行加权平均,离插值点越近的样本点赋予的权重越大. 设平 ...
- python 模块基础介绍
从逻辑上组织代码,将一些有联系,完成特定功能相关的代码组织在一起,这些自我包含并且有组织的代码片段就是模块,将其他模块中属性附加到你的模块的操作叫做导入. 那些一个或多个.py文件组成的代码集合就称为 ...
- C# BlockCollection
1.BlockCollection集合是一个拥有阻塞功能的集合,它就是完成了经典生产者消费者的算法功能. 它没有实现底层的存储结构,而是使用了IProducerConsumerCollection接口 ...
- postgresql是如何处理死连接(转)
在数据库postgresql中,一个客户端到服务器连接实际上是一个tcp socket连接,tcp连接是虚连接,一方非正常退出(如断电),另一方会继续维持这个连接. 举个例子,一个客户端电脑正常连 ...
- Android网络请求通信之Volley
一.Volley简介 Volley网络框架是Google公司在2013年发布的一款Android平台上的网络请求通信库.以下是对Volley的简单归纳. Volley的优点: 使网络通信更快.更简单. ...
- 使用github pages, hexo搭建个人博客教程
具体的原理性的东西就不说了直接上教程,怕等下自己忘了. 一. github 阶段 申请一个github 账号并成功登录进去. 创建一个名字为xxx.github.io的空项目. 二. hexo 阶段 ...
- Python系统命令操作
系统命令 1.call 执行命令,返回状态码 ret = subprocess.call(['ls', '-l'], shell=False) ret = subprocess.call('ls -l ...
- tornado 第二种路由方法(装饰器)
#!/usr/bin/env python # _*_coding:utf-8 _*_ import tornado.ioloop import tornado.web application = t ...
- ucenter用户登录过程
以用户登录为例介绍,其它注销,改密码,消息,头像,好友均类同. 从用户xxx在某一应用程序的login.php,输入用户名,密码讲起.先用uc_user_login函数到uc_server验证此用户和 ...