Codeforces Round #547 (Div. 3) D. Colored Boots
链接:https://codeforces.com/contest/1141/problem/D
题意:
给连个n长度的字符串。
求两个字符串相同字符对应位置的对数,并挨个打印。
字符:?可以代替任何字符。
思路:
对第一个字符串建立字符与位置的映射。
再处理第二个字符。
同时第二个字符中的‘?'不做处理。
全部遍历完了以后,再处理?的情况。
代码:
#include <bits/stdc++.h> using namespace std; typedef long long LL; map<char, queue<int> > M;
vector<pair<int, int> > res;
queue<int> other; int main()
{
int n;
cin >> n;
string a, b;
cin >> a;
for (int i = 0;i < n;i++)
M[a[i]].push(i + 1);
cin >> b;
for (int i = 0;i < n;i++)
{
if (b[i] != '?')
{
if (M[b[i]].size() > 0)
{
res.push_back(make_pair(M[b[i]].front(), i + 1));
M[b[i]].pop();
}
else if (M['?'].size() > 0)
{
res.push_back(make_pair(M['?'].front(), i + 1));
M['?'].pop();
}
}
else
other.push(i + 1);
}
for (int i = 0;i <= 25;i++)
{
while (M[(char)(i + 'a')].size() && other.size())
{
res.push_back(make_pair(M[(char)(i + 'a')].front(), other.front()));
M[(char)(i + 'a')].pop();
other.pop();
}
}
while (M['?'].size() && other.size())
{
res.push_back(make_pair(M['?'].front(), other.front()));
M['?'].pop();
other.pop();
}
cout << res.size() << endl;
for (auto x : res)
cout << x.first << ' ' << x.second << endl; return 0;
}
Codeforces Round #547 (Div. 3) D. Colored Boots的更多相关文章
- Codeforces Round #547 (Div. 3) D. Colored Boots (贪心,模拟)
题意:有两个字符串,两个字符串中的相同字符可以相互匹配,\(?\)可以和任意字符匹配,输出最大匹配的字符数量和它们分别两个字符串中的位置. 题解:很容易贪心,我们先遍历第一个字符串,然后在第二个字符串 ...
- Codeforces Round #547 (Div. 3) 题解
Codeforces Round #547 (Div. 3) 题目链接:https://codeforces.com/contest/1141 A,B咕咕了... C. Polycarp Restor ...
- E. Superhero Battle Codeforces Round #547 (Div. 3) 思维题
E. Superhero Battle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #547 (Div. 3) G 贪心
https://codeforces.com/contest/1141/problem/G 题意 在一棵有n个点的树上给边染色,连在同一个点上的边颜色不能相同,除非舍弃掉这个点,问最少需要多少种颜色来 ...
- Codeforces Round #547 (Div. 3) F 贪心 + 离散化
https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 ...
- Codeforces Round #547 (Div. 3) D
http://codeforces.com/contest/1141/problem/D 题目大意: 鞋子匹配,用一个小写字母表示一种颜色.L[i]表示左脚的颜色,R[i]表示右脚的颜色,只有当L[i ...
- Codeforces Round #547 (Div. 3) B.Maximal Continuous Rest
链接:https://codeforces.com/contest/1141/problem/B 题意: 给n个数,0代表工作,1代表休息,求能连续最大的休息长度. 可以连接首尾. 思路: 求普通连续 ...
- Codeforces Round #547 (Div. 3) A.Game 23
链接:https://codeforces.com/contest/1141/problem/A 题意: 给n和m,有两种操作:将n×2 或 n×3,求最少的乘法次数由n得到m. 不能得到时为-1. ...
- Codeforces Round #547 (Div. 3)
我老人家走了四公里吃个汉堡还没吃成.垃圾肯德基.垃圾春分半价桶. 蜜雪冰城百香果加冰+烤串真是爽死了.原来二十多块钱可以吃的这么爽. A: #include <bits/stdc++.h> ...
随机推荐
- poj3461 Oulipo —— KMP
题目链接:http://poj.org/problem?id=3461 代码如下: #include<cstdio>//poj 3461 kmp #include<cstring&g ...
- powerbuilder
PowerBuilder美国Sybase公司研制的一种新型.快速开发工具,是客户机/服务器结构下,基于Windows3.x.Windows95和WindowsNT的一个集成化开发工具.它包含一个直观的 ...
- ffmpeg av_interleaved_write_frame Operation not permitted
今天在使用ffmpeg时出现了Operation not permitted通过增加打印信息发现是在av_interleaved_write_frame出现的问题, 昨天还没出现这个问题,很奇怪,就把 ...
- __FILE__,__LINE__,__func__ 真好用,DEBUG利器啊!
我是不喜欢用类似VC下的F5,F10.曾经很喜欢用.被代码逻辑逼的没招了.所以不喜欢用了. 比如,错误是根据动态数据,产生的行为错误,无论是该写的未写,还是不该写的写了.指针跑飞什么等等,无非就是上述 ...
- android布局中使用include及需注意点
在android布局中,使用include,将另一个xml文件引入,可作为布局的一部分,但在使用include时,需注意以下问题: 一.使用include引入 如现有标题栏布局block_header ...
- ip策略路由
ip route 只是基于目的地址的路由选择 ip rule 路由策略,控制路由选择,可根据源地址,源IP等进行路由选择 路由策略由选择符合操作组成 ip rule add 添加策略 ip r ...
- php 有时候难以输出显示的信息可以用ob缓冲区来做
有时候一些难以打印的信息可以通过缓冲区来做,比如手机扫码上的信息看不到这种, 当然也可以通过fiddler来抓包,也可以看到这些信息,直接上代码: <?php ob_start(); //开启缓 ...
- JSP提交表单的几种方法
1.通过<form action="url"><input type="submit"></form>按钮方式提交 这种方式 ...
- Asset Catalog Help (三)---Adding Image Sets
Adding Image Sets Organize versions of your images in image sets, which you can add to an asset cata ...
- 【Hadoop】HDFS笔记(二):HDFS的HA机制和Federation机制
HA解决了HDFS的NameNode的单点问题: Federation解决了整个HDFS集群中只有一个名字空间,并且只有单独的一个NameNode管理所有DataNode的问题. 一.HA机制(Hig ...