CodeForces 518B Tanya and Postcard 计数
来源:互联网 发布:席晓辉 知乎 编辑:程序博客网 时间:2024/05/29 15:10
先来错误代码, Wrong answer test 8:
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <map>using namespace std;const int maxn = 200000 + 24;char s[maxn], t[maxn], ans[maxn];map<char, int> mp;int main() {scanf("%s%s", s, t);mp.clear();int len = strlen(t);for(int i = 0; i < len; ++i) {mp[t[i]]++;}int ans1 = 0, ans2 = 0;len = strlen(s);for(int i = 0; i < len; ++i) {if(mp[s[i]] > 0) {ans1++;mp[s[i]]--;}else if(mp[s[i]] == 0) {if(s[i] >= 'a' && s[i] <= 'z' && mp[s[i]-32] > 0) { ans2++; mp[s[i]-32]--; }if(s[i] >= 'A' && s[i] <= 'Z' && mp[s[i]+32] > 0) { ans2++; mp[s[i]+32]--; }}}printf("%d %d\n", ans1, ans2);}
一直wrong answer test 8,最后终于找出了一组样例通不过:
aaaaAAAA
AAAAaaBB
答案应该是: 6 0然而以上代码运行出结果为 4 2;
所以应该先找出YAY!的值,跑两次循环就可以:
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <map>using namespace std;const int maxn = 200000 + 24;char s[maxn], t[maxn], ans[maxn];map<char, int> mp;int main() {scanf("%s%s", s, t);mp.clear();int len = strlen(t);for(int i = 0; i < len; ++i) {mp[t[i]]++;}int ans1 = 0, ans2 = 0;len = strlen(s);for(int i = 0; i < len; ++i) {if(mp[s[i]] > 0) {ans1++;mp[s[i]]--;s[i] = 0;}}for(int i = 0; i < len; ++i) {if(s[i] >= 'a' && s[i] <= 'z' && mp[s[i]-32] > 0) { ans2++; mp[s[i]-32]--; }if(s[i] >= 'A' && s[i] <= 'Z' && mp[s[i]+32] > 0) { ans2++; mp[s[i]+32]--; }}printf("%d %d\n", ans1, ans2);}
0 0
- CodeForces 518B Tanya and Postcard 计数
- codeforces 518B Tanya and Postcard
- codeforces 518B Tanya and Postcard
- CodeForces 518B Tanya and Postcard
- CF 518B(Tanya and Postcard-计数统计)
- CodeForces - 518B Tanya and Postcard(水题)
- B. Tanya and Postcard
- Codeforces Round #293 (Div. 2) -- B. Tanya and Postcard
- Codeforces Round #293 (Div. 2) B. Tanya and Postcard
- 518B - Tanya and Postcard【哎还是string】
- Codeforces Round #324 B Kolya and Tanya
- codeforces 584B Kolya and Tanya
- B. Kolya and Tanya
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya
- Codeforces Round #324 (Div. 2)B. Kolya and Tanya
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya
- 17.4节练习
- Linux学习总结(10)——Linux查看CPU和内存使用情况
- AccessController.doPrivileged解释
- 关于ISI、SCI、EI、IEEE、Elsevier、Springer的理解
- TestNG介绍
- CodeForces 518B Tanya and Postcard 计数
- android数字签名的创建和获取签名信息
- 分布式-远程部署的RMI
- 二叉树的建立与遍历方法
- linux tomcat PermGen space
- SpringMVC+Mybatis整合搭建
- js字符串加入千分号
- controller
- Onvif PTZ简介