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. python类(2)

    #从python开始学习编程 学习笔记 以后看书时注意一下书上表述:好像是类属性attribute,对象特性property,对象方法 1.对于一个类下的全部个体来说,某些属性可能存在个体差异.不是所 ...

  2. 18 11 26 用多进程 多线程 携程 实现 http 服务器的创建

    下面是一个  多进程 服务器的创建 import socket import re import multiprocessing def service_client(new_socket): &qu ...

  3. h5-全屏插件

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Go get unrecognized import path "gopkg.in/yaml.v2"

    安装gin: go get -u github.com/gin-gonic/gin 出现错误: package gopkg.in/yaml.v2: unrecognized import path & ...

  5. findbugs报OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE的修改实例

    先看出问题的一段代码 public void encode(String xxxPath, String thumbTmpPath, String imageType) { LOGGER.info(& ...

  6. one_day_one_linuxCmd---sz命令

    <坚持每天学习一个 linux 命令,今天我们来学习 sz && rz 命令> 前言:我们一般通过 ssh 客户端来进行远程登录和管理的,windows主机使用 ssh 登 ...

  7. Springboot整合mongodb时无法连接数据库

    由于之前没有接触过mongodb,最近在学习时遇到了一些问题.用yml配置mongodb如下: spring: application: name:xc-service-manage-cms data ...

  8. 定时任务莫名停止,Spring 定时任务存在 Bug?

    专注于Java领域优质,技术欢迎关注 作者: 鸭血粉丝 来自:Java极客技术 Hello~各位读者新年好,我是鸭血粉丝(大家可以称呼我为「阿粉」).这里阿粉给大家拜个年,祝大家蒸蒸日上烫烫烫,年年有 ...

  9. App的工程框架

    对于我刚下载的Android studio,来说一说它的框架结构  Project项目结构: .gradle:Gradle编译系统,版本由wrapper指定 .idea:IDE所需要的文件 .app: ...

  10. 选择排序&冒泡排序

    //直接选择排序 #include<stdio.h> void SelectionSort(int arr[],int len) { int i,j; int k,min; int tem ...