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> ...
随机推荐
- js程序开发-3
<h1>Date()类型</h1> 获取日期和时间 getDate() 获取日 1-31 getDay () 获取星期 0-6 getMonth () 获取月 0-11 get ...
- ffmpeg遇到inttypes.h和UINT64_C
http://blog.csdn.net/cll131421/article/details/7763657 编译过程:错误一:无法打开包括文件:“inttypes.h”: No such file ...
- python学习笔记:第四天( 字符串)
Python3 字符串 字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 在Python2中,普通字符串是以8位ASCII码进行存储的,而Unicode字 ...
- php排序方法之冒泡排序
//冒泡排序法 $arr = array(3,55,45,2,67,76,6.7,-65,85,4); function bubblingSort($arr){ for ( $i=0; $i<c ...
- 【概念】SVG(1)
ok,我们讲讲svg 学习前提:懂HTML和基本的XML SVG简介: 1.SVG全称Scable Vector Graphic,可伸缩的矢量图 2.SVG用于定义针对于Web的基于矢量的图形 3.S ...
- HTML标题和段落
HTML标题 通过<h1> - <h6> 等标签进行定义 <h1>一标题</h1> <h2>二标题</h2> <h3> ...
- 使用NSTask调用shell
- (NSString *)cmd:(NSString *)cmd { // 初始化并设置shell路径 NSTask *task = [[NSTask alloc] init]; [task set ...
- Can't locate Log/Dispatch.pm in @INC
记录一下配置mha的时候遇到的错误,使用perl模块发送邮件的时候报以下错误: # masterha_check_ssh --conf=/data/mha/app1.cnf Can't locate ...
- BZOJ_3545_[ONTAK2010]Peaks_主席树+倍增+kruscal重构树+dfs序
BZOJ_3545_[ONTAK2010]Peaks_主席树+倍增+kruscal重构树 Description 在Bytemountains有N座山峰,每座山峰有他的高度h_i.有些山峰之间有双向道 ...
- java-swing-JTextComponent
package com.http; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Swi ...