CF 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
题目太难懂,三个人读出三种意思。
#include <iostream>
#include <cctype>
#include <cstring>
#include <cstdio>
using namespace std; int T_L_HAVE[] = {};
int S_L_HAVE[] = {};
int T_U_HAVE[] = {};
int S_U_HAVE[] = {}; int main(void)
{
string s;
string t;
int len_s,len_t;
int sum_yay = ;
int sum_whoops = ; cin >> s >> t;
len_s = s.size();
len_t = t.size(); for(int i = ;i < len_t;i ++)
if(islower(t[i]))
T_L_HAVE[t[i] - 'a'] ++;
else
T_U_HAVE[t[i] - 'A'] ++; for(int i = ;i < len_s;i ++)
if(islower(s[i]))
S_L_HAVE[s[i] - 'a'] ++;
else
S_U_HAVE[s[i] - 'A'] ++; for(int i = ;i < len_s;i ++)
{
if(islower(s[i]) && T_L_HAVE[s[i] - 'a'])
{
S_L_HAVE[s[i] - 'a'] --;
T_L_HAVE[s[i] - 'a'] --;
sum_yay ++;
}
else if(isupper(s[i]) && T_U_HAVE[s[i] - 'A'])
{
S_U_HAVE[s[i] - 'A'] --;
T_U_HAVE[s[i] - 'A'] --;
sum_yay ++;
}
} for(int i = ;i < len_s;i ++)
{
if(islower(s[i]) && S_L_HAVE[s[i] - 'a'] && T_U_HAVE[s[i] - - 'A'])
{
S_L_HAVE[s[i] - 'a'] --;
T_U_HAVE[s[i] - - 'A'] --;
sum_whoops ++;
}
else if(isupper(s[i]) && S_U_HAVE[s[i] - 'A'] && T_L_HAVE[s[i] + - 'a'])
{
S_U_HAVE[s[i] - 'A'] --;
T_L_HAVE[s[i] + - 'a'] --;
sum_whoops ++;
}
} cout << sum_yay << ' ' << sum_whoops << endl; return ;
}
CF Tanya and Postcard的更多相关文章
- CodeForces 518B. Tanya and Postcard
B. Tanya and Postcard time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 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 ...
- 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)
A. Vitaly and Strings 题意:两个字符串s,t,是否存在满足:s < r < t 的r字符串 字符转处理:字典序排序 很巧妙的方法,因为s < t,只要找比t字典 ...
- codeforces518B
Tanya and Postcard CodeForces - 518B 有个小女孩决定给他的爸爸寄明信片.她已经想好了一句话(即长度为n的字符串s),包括大写和小写英文字母.但是他不会写字,所以她决 ...
- CF 1005A Tanya and Stairways 【STL】
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairw ...
- CF 584B Kolya and Tanya
题目大意:3n个人围着一张桌子,给每个人发钱,可以使1块.2块.3块,第i个人的金额为Ai.若存在第个人使得Ai + Ai+n + Ai+2n != 6,则该分配方案满足条件,求所有的满足条件的方案数 ...
- CF 508D Tanya and Password(无向图+输出欧拉路)
( ̄▽ ̄)" //不知道为什么,用scanf输入char数组的话,字符获取失效 //于是改用cin>>string,就可以了 //这题字符的处理比较麻烦,输入之后转成数字,用到函 ...
随机推荐
- homework-05 GoldNumberServer
作业要求 这次作业要求实现一个黄金数游戏服务器,游戏流程如下,每个client向服务器提交一个有理数,服务器接收到所有客户端的提交后计算这些数字的平均数,再将其乘以黄金分割得到一个GoldNumber ...
- HDU 5792 World is Exploding (树状数组)
World is Exploding 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5792 Description Given a sequence ...
- centos 使用mutt 命令发送邮件,随笔非教程
#按照mutt yum -y install mutt #发送邮件 echo .com -s "邮件主题" -a 附件本地地址
- Spring Autowiring by Type
In Spring, "Autowiring by Type" means, if data type of a bean is compatible with the data ...
- Oracle & Sun
2010s January 27, 2010: Oracle acquires Sun Microsystems.
- js奇葩错误
局部刷新中显示图片: 错误写法:var innerDiv = "<p class='town_con' id='city1'>"; var d ...
- Oracle超出最大连接数问题及解决
用过Oracle的应该都熟悉如何查看和设置Oracle数据库的最大连接数.这里就再啰嗦一遍. 查看当前的连接数,可以用select count(*) from v$process;设置的最大连接数(默 ...
- Struts2内建校验器(基于校验框架的文件校验)
位于xwork-2.0.4.jar压缩包中( com.opensymphony.xwork2.validator.validators)有个文件default.xml ,该文件中定义了Struts2框 ...
- 使用Filter防止浏览器缓存页面或请求结果
仅仅须要两步: 1.定义一个Filter: /** * 防止浏览器缓存页面或请求结果 * @author XuJijun * */ public class NoCacheFilter impleme ...
- Codeforces Gym 100418A A - A+-B java高精度
A - A+-BTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.acti ...