http://codeforces.com/problemset/problem/1141/D
题意:看样例就能懂了。。。
题解:用容器/结构体/二维数组存第一个字符串每个字符出现的位置,同时也要记录问号的位置,用于无字符匹配时匹配问号。
/* ***********************************************
Author :pall_scall
Created Time :2019年03月30日 星期六 10时16分22秒
File Name :cf.cpp
************************************************ */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
using namespace std;
typedef long long ll;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const double pi = acos(-1.0);
vector<int>v[30];
int n;
char s1[150005],s2[150005];
int l[150005],r[150005];
int wen[150005];
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d",&n);
scanf("%s",s1+1);
//int len = strlen(s1+1);
//cout<<len<<endl;
for(int i = 1; i <= n; i++){
if(s1[i] == '?'){
v[0].push_back(i);
continue;
}
int pos = s1[i]-'a'+1;
v[pos].push_back(i);
}
scanf("%s",s2+1);
int ans = 0;
int cnt = 0;
for(int i = 1; i <= n; i++){
if(s2[i] == '?'){
wen[++cnt] = i;
continue;
}
int res = s2[i]-'a'+1;
if(v[res].size() != 0){
l[ans] = *v[res].begin();
r[ans++] = i;
v[res].erase(v[res].begin());
}else{
if(v[0].size() != 0){
l[ans] = *v[0].begin();
r[ans++] = i;
v[0].erase(v[0].begin());
}
}
}
int id = 0;
for(int i = 1; i <= 26; i++){
if(cnt == 0) break;
for(int j = 0; j < v[i].size(); j++){
l[ans] = v[i][j];
r[ans++] = wen[cnt];
cnt--;
id = max(id,j);
if(cnt == 0) break;
}
}
int p = v[0].size();
int tot = min(p,cnt);
for(int i = 0; i < tot; i++){
l[ans] = v[0][id];
r[ans++] = wen[cnt];
cnt--;
id++;
}
printf("%d\n",ans);
for(int i = 0; i < ans; i++){
printf("%d %d\n",l[i],r[i]);
}
return 0;
}