There are nn left boots and nn right boots. Each boot has a color which is denoted as a lowercase Latin letter or a question mark ('?'). Thus, you are given two strings ll and rr, both of length nn. The character lili stands for the color of the ii-th left boot and the character riri stands for the color of the ii-th right boot.

A lowercase Latin letter denotes a specific color, but the question mark ('?') denotes an indefinite color. Two specific colors are compatible if they are exactly the same. An indefinite color is compatible with any (specific or indefinite) color.

For example, the following pairs of colors are compatible: ('f', 'f'), ('?', 'z'), ('a', '?') and ('?', '?'). The following pairs of colors are notcompatible: ('f', 'g') and ('a', 'z').

Compute the maximum number of pairs of boots such that there is one left and one right boot in a pair and their colors are compatible.

Print the maximum number of such pairs and the pairs themselves. A boot can be part of at most one pair.

Input

The first line contains nn (1≤n≤1500001≤n≤150000), denoting the number of boots for each leg (i.e. the number of left boots and the number of right boots).

The second line contains the string ll of length nn. It contains only lowercase Latin letters or question marks. The ii-th character stands for the color of the ii-th left boot.

The third line contains the string rr of length nn. It contains only lowercase Latin letters or question marks. The ii-th character stands for the color of the ii-th right boot.

Output

Print kk — the maximum number of compatible left-right pairs of boots, i.e. pairs consisting of one left and one right boot which have compatible colors.

The following kk lines should contain pairs aj,bjaj,bj (1≤aj,bj≤n1≤aj,bj≤n). The jj-th of these lines should contain the index ajaj of the left boot in the jj-th pair and index bjbj of the right boot in the jj-th pair. All the numbers ajaj should be distinct (unique), all the numbers bjbj should be distinct (unique).

If there are many optimal answers, print any of them.

Examples
input

Copy
10
codeforces
dodivthree
output

Copy
5
7 8
4 9
2 2
9 10
3 1
input

Copy
7
abaca?b
zabbbcc
output

Copy
5
6 5
2 3
4 6
7 4
1 2
input

Copy
9
bambarbia
hellocode
output

Copy
0
input

Copy
10
code??????
??????test
output

Copy
10
6 2
1 6
7 3
3 5
4 8
9 7
5 1
2 4
10 9
8 10
题解:用vector记录a数组中每个字符和其出现的位置,a数组中问号的位置。定义查找函数:bool Find(int s, int x)//在a数组里找与b数组中下标为x对应的字符s。
遍历b数组,ans的pair vector记录答案,在Find函数中记录~~看代码实现:
感受:一开始不太熟悉vector,做完这道题感觉自己学到了很多东西,还有能力有了很大的提升呢~~
#include <iostream>
#include<vector>
using namespace std;
int n;
char a[];
char b[];
vector<int> v[], sp;//v[i]记录字符ASCII码值为i的位置,sp记录问号的位置
vector<pair<int, int> > ans;//ans记录答案,pair分别对应a,b所对应的位置
bool Find(int s, int x)//在a数组里找与b数组中下标为x对应的字符s
{
if (v[s].empty())//如果a数组里面没有对应的字符s了(ASCII码转换),就是没找到
return ;
ans.emplace_back(v[s].back(), x);//记录字符在第一个串和第二个串的位置
v[s].pop_back();//将记录的位置去掉
return ;
}
int main()
{
cin >> n;
for (int i = ; i <= n; i++)//字符串为了方便用下标来输入
{
cin >> a[i];
v[a[i]].push_back(i);//将每一个a[i]字符对应的位置放入v的vector
}
for (int i = ; i <= n; i++)
cin >> b[i];
for (int i = ; i <= n; i++)//进行遍历
{
if (b[i] == '?')//记录问号的位置
sp.push_back(i);
else if (!Find(b[i], i))//如果不是问号,并且a中没有对应的字符(不包括问号)
Find('?', i);//就将1个问号与之匹配
}
for (vector<int>::iterator it = sp.begin(); it != sp.end(); it++)//遍历问号的位置
{
for (int j = ; j < ; j++)//找到一个字符(任意)与问号对应
{
if (Find(j, *it))
break;
}
}
cout << ans.size() << endl;//总个数
for(vector<pair<int,int> >::iterator it=ans.begin();it!=ans.end();it++)//遍历
cout << (*it).first << " " <<(*it).second << endl;
return ;
}

D. Colored Boots(STL)的更多相关文章

  1. C++标准模板库(STL)和容器

    1.什么是标准模板库(STL)? (1)C++标准模板库与C++标准库的关系 C++标准模板库其实属于C++标准库的一部分,C++标准模板库主要是定义了标准模板的定义与声明,而这些模板主要都是 类模板 ...

  2. 【常用技巧】标准模板库(STL)

    [常用技巧]标准模板库(STL) 在前几个章节中我们已经使用了诸如队列.堆.堆栈.vector 等标准模板库中的模板,切身感受到了它给我们带来的极大便利.在本节中,我们还要介绍两种标准模板——stri ...

  3. C++ 标准模板库(STL)——容器(Containers)的用法及理解

    C++ 标准模板库(STL)中定义了通用的模板类和函数,这些模板类和函数可以实现多种流行和常用的算法和数据结构,如向量(vector).队列(queue).栈(stack).set.map等.这次主要 ...

  4. Three.js 3D打印数据模型文件(.STL)载入中

    3DPrint是现在和未来10年度科技产品的主流之中.广泛的. 对于电子商务类3D打印网站.一个主要功能就是商品3D呈现的方式,那是,3D数据可视化技术. HTML5(WebGL)它可以用于构建3D查 ...

  5. C++标准模板库(STL)之Vector

    在C中,有很多东西需要自己实现.C++提供了标准模板库(Standard Template Libray,STL),其中封装了很多容器,不需要费力去实现它们的细节而直接调用函数来实现功能. 具体容器链 ...

  6. C++ 标准库和标准模板库(STL)

    转自原文http://blog.csdn.net/sxhelijian/article/details/7552499 一.C++标准库 C++标准库的内容分为10类,分别是(建议在阅读中,将你已经用 ...

  7. 离散化——化不可能为可能(STL)

    所谓离散,就是化连续为不连续,使得我们某种枚举的方法得以实现. 当然,离散还能够帮助我们将某些数据范围很大达到2^16,但是这些数据并不多(例如才1000+),我们可以把数据进行离散,保持他们之间的相 ...

  8. C++ 标准模板库介绍(STL)

    1. STL 基本介绍 C++ STL(标准模板库)是惠普实验室开发的一系列软件的统称,是一套功能强大的 C++ 模板类.STL的目的是为了标准化组件,这样就不用重新开发,让后来者可以使用现成的组件, ...

  9. 标准模板库(STL) map —— 初始化问题

    map 容器没有:.reverse成员: map 是关联式容器,会根据元素的键值自动排序: map 容器不是连续的线性空间: 标准 STL 使用 RB-tree 为底层机制 ⇒ 自动排序(关于键值): ...

随机推荐

  1. jQuery选择器全解析

    1. 基本选择器 1.1 id选择器:$(#id) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...

  2. AD软件将PCB中的元器件旋转45度

  3. GPLT L3-021 神坛

    在古老的迈瑞城,巍然屹立着 n 块神石.长老们商议,选取 3 块神石围成一个神坛.因为神坛的能量强度与它的面积成反比,因此神坛的面积越小越好.特殊地,如果有两块神石坐标相同,或者三块神石共线,神坛的面 ...

  4. 解决configure: error: C++ compiler cannot create executables问题

    参考 yum install gcc gcc++ 呵呵,这样的话还是有组件没有安装完整的.再执行一下这个命令就可以解决问题. yum install gcc gcc-c++ gcc-g77

  5. Maven:程序包不存在,找不到符号

    maven build时出现了以下的错误: 程序包xx.xx不存在,xxx找不到符号 原因一:DAO层依赖Service接口层的Bean类,在pom.xml中添加了对Service的依赖,也因此引入了 ...

  6. .NET CORE 热更新,否则提示DLL文件在使用中

    1.创建空目录,取名updatesite,里面放置app_ffline.htm文件,网站更新中访问使用,内容随意 2.updatesite目录下面创建Release目录,用于放置更新的dll文件 3. ...

  7. (转)Java并发编程:阻塞队列

    Java并发编程:阻塞队列 在前面几篇文章中,我们讨论了同步容器(Hashtable.Vector),也讨论了并发容器(ConcurrentHashMap.CopyOnWriteArrayList), ...

  8. SQL基础教程(第2版)第6章 函数、谓词、CASE表达式:练习题

    END) AS low_price, END) AS mid_price, END) AS high_price FROM Product; 6_2.sql

  9. Vue.js——2.第一个Vue程序

    代码 <div id="app"> <p>{{msg}}</p> </div> <script> let vm=new ...

  10. 一个支持种子、磁力、迅雷下载和磁力搜索的APP源代码

    磁力搜索网站2020/01/12更新 https://www.cnblogs.com/cilisousuo/p/12099547.html 一个支持种子.磁力.迅雷下载和磁力搜索的APP源代码 Lic ...