codeforces 518B. Tanya and Postcard 解题报告
题目链接:http://codeforces.com/problemset/problem/518/B
题目意思:给出字符串 s 和 t,如果 t 中有跟 s 完全相同的字母,数量等于或者多过 s,就将 s 这个数量加到 YAY! 的答案里,少于的话就加 t 中有的数量;如果 t 中有跟 s 相同的字母但是大小写不对应(例如A-a,z-Z),就加到 WHOOPS 的答案里。
举个例子就很容易明白了。例如 s 和 t 分别为:
ncMeXssLHS
uwyeMcaFatpInZVdEYpwJQSnVxLK
字符s、n、c、M、e、L、S 两者都有,于是 ans_YAY = 6;XssH中 X 在字符串 t 中 有小写字母x,其他的ssH 在字符串 t 中根本就没有!
其实...........做virtual 的时候没有看懂题目 = =!是直接看测试数据看出来的。
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".
这句话不仅内有乾坤,还意味深长呢~~~~~看懂题目是很重要滴!
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = 2e5 + ;
const int maxl = ;
char s[maxn], t[maxn];
int cs[maxl], ct[maxl]; inline int get_id(char ch)
{
if (ch >= 'a' && ch <= 'z')
return ch - 'a';
return ch-'A' + ; // 大写字母从下标26开始
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE while (scanf("%s%s", s, t) != EOF) {
memset(cs, , sizeof(cs));
int ls = strlen(s), lt = strlen(t);
for (int i = ; i < ls; i++)
cs[get_id(s[i])]++;
memset(ct, , sizeof(ct));
for (int i = ; i < lt; i++)
ct[get_id(t[i])]++; int ans_YAY = ;
for (int i = ; i < maxl; i++) {
int minuend = min(cs[i], ct[i]);
cs[i] -= minuend, ct[i] -= minuend;
ans_YAY += minuend;
}
int ans_WHOOPS = ;
for (int i = ; i < ; i++) {
int added = min(cs[i], ct[i+]) + min(cs[i+], ct[i]);
ans_WHOOPS += added;
}
printf("%d %d\n", ans_YAY, ans_WHOOPS);
}
return ;
}
codeforces 518B. 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 518B Tanya and Postcard (题意,水题)
题意:给定两个字符串,然后从第二个中找和第一个相同的,如果大小写相同,那么就是YAY,如果大小写不同,那就是WHOOPS.YAY要尽量多,其次WHOOPS也要尽量多. 析:这个题并不难,难在读题懂题意 ...
- Codeforces Educational Round 92 赛后解题报告(A-G)
Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...
- codeforces 476C.Dreamoon and Sums 解题报告
题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...
- Codeforces Round #382 (Div. 2) 解题报告
CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...
- codeforces 507B. Amr and Pins 解题报告
题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...
- codeforces 500B.New Year Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...
- codeforces B. Xenia and Ringroad 解题报告
题目链接:http://codeforces.com/problemset/problem/339/B 题目理解不难,这句是解题的关键 In order to complete the i-th ta ...
- Codeforces Round #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
随机推荐
- 【转载】Ubuntu 系列安装 Docker
系统要求 Docker 支持以下版本的Ubuntu操作系统: Ubuntu Xenial 16.04 (LTS) Ubuntu Wily 15.10 Ubuntu Trusty 14.04 (LTS) ...
- [译]在AngularJS中何时应该使用Directives,Controllers或者Service
原文: http://kirkbushell.me/when-to-use-directives-controllers-or-services-in-angular/ Services Servic ...
- python文件I/O(转)
Python 文件I/O 本章只讲述所有基本的的I/O函数,更多函数请参考Python标准文档. 打印到屏幕 最简单的输出方法是用print语句,你可以给它传递零个或多个用逗号隔开的表达式.此函数把你 ...
- php——文件下载
php——.doc 文件下载 先看简单实例: 同目录下有两个文件ib.php,test.php与供下载 .doc 文件: test.php文件内容: <?php $attr = glob(&qu ...
- STM32F103xx bxCAN(Basic Extended CAN) 滤波机制
一.背景 最近一个项目需要使用STM32F103xx实现CAN通信,而CAN总线的消息滤波在各个MCU上有不同机制, 譬如,SJA1000为标识符位屏蔽滤波机制,NXP的LPC17xx系列为标识符列表 ...
- 2015baidu复赛2 连接的管道(mst && 优先队列prim)
连接的管道 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- SCP命令
\ svn 删除所有的 .svn文件 find . -name .svn -type d -exec rm -fr {} \; linux之cp/scp命令+scp命令详解 名称:cp 使用权限: ...
- CHAP算法C++实现
CHAP是一种挑战响应式协议. CHAP全称为:Challenge Handshake Authentication Protocol. CHAP密码 = 一个字节的标识符 + MD5(一个字节的标识 ...
- Redis学习笔记二:单机数据库的实现
1. 数据库 服务器中的数据库 Redis服务器将所有数据库都保存在服务器状态redis.h/redisServer结构的db数组中,db数组的每个项都是一个redis.h/redisDb结构,每个r ...
- fontconfig编译出错
编译fontconfig编译时出错: 出错configure: error: You must have freetype installed; see http://www.freetype.org ...