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,就可以了 //这题字符的处理比较麻烦,输入之后转成数字,用到函 ...
随机推荐
- Nginx的代理和反向代理
什么是代理? 代理是为网络用户代理了来访问网络的,比如Google agent代理FQ. 什么是反向代理? 以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服 ...
- Java设计模式系列之迭代器模式
迭代器模式定义 迭代器模式(Iterator),提供一种方法顺序访问一个聚合对象中的各种元素,而又不暴露该对象的内部表示. 迭代器模式的角色构成 (1)迭代器角色(Iterator):定义遍历元素所需 ...
- CodeForces 689A Mike and Cellphone (模拟+水题)
Mike and Cellphone 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/E Description While sw ...
- [iOS基础控件 - 6.12.1] QQ菜单管理 UITabBarController 控制器管理
A.需求 1.类似QQ.微信顶部或者底部的窗口转换导航条 2.给每个页面添加相应内容 B.UITabBarController 1.基本概念: (1)内容高度 iOS7之前内容高度为:屏幕高度 - ...
- 转载IEnumerable与IEnumerator区别
public interface IEnumerable { IEnumerator GetEnumerator(); } public interface IEnumerator { ...
- 在C#调用C++的DLL简析(一)——生成非托管dll
经过一晚上的折腾,还是下点决心将些许的心得写下来,以免以后重复劳动. C#与C/C++相 比,前者的优势在于UI,后者的优势在于算法,C++下的指针虽然恶心,若使用得当还是相当方便的,最重要的问题是, ...
- 十六进制转十进制 - C
我们经常碰到16进制数转10进制的情况,使用下面的C程序即可完成上述工作. 那么他是怎样的工作原理呢? 6.2.5 十六进制数转换成十进制数 16进制就是逢16进1,但我们只有0~9这十个数字,所以我 ...
- socket的shutdown与close
shutdown原型 int shutdown(int socket, int how); socket 指定socket的文件描述符 how 指定shutdown的类型 SHUT_RD 禁止读 ...
- VC的文件操作
各种关于文件的操作在程序设计中是十分常见,如果能对其各种操作都了如指掌,就可以根据实际情况找到最佳的解决方案,从而在较短的时间内编写出高效的代码,因而熟练的掌握文件操作是十分重要的.本文将对Visua ...
- Node.js和mybatis分别实现mysql中like变量模糊查询
<!-- mybatis --> <where> <if test="varName != '' and varName != null" > ...