Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 150000 + 100;
- map<char, queue<int>> cnt1, cnt2;
- int n;
- char l[N], r[N];
- inline void read(){
- cin >> n;
- for(int i = 0; i < n; ++i){
- cin >> l[i];
- cnt1[l[i]].push(i);
- }
- for(int i = 0; i < n; ++i){
- cin >> r[i];
- cnt2[r[i]].push(i);
- }
- }
- int main(void){
- read();
- vector<pair<int, int>> ans;
- for(char i = 'a'; i <= 'z'; ++i){
- if(!cnt1[i].empty() && !cnt2[i].empty()){
- while(!cnt1[i].empty() && !cnt2[i].empty()){
- int x = cnt1[i].front(), y = cnt2[i].front();
- cnt1[i].pop(), cnt2[i].pop();
- ans.push_back(make_pair(x + 1, y + 1));
- if(cnt2[i].empty() || cnt1[i].empty()){
- break;
- }
- }
- }
- }
- if(!cnt1['?'].empty()){
- for(char i = 'a'; i <= 'z'; ++i){
- if(!cnt1['?'].empty() && !cnt2[i].empty()){
- while(!cnt1['?'].empty() && !cnt2[i].empty()){
- int x = cnt1['?'].front(), y = cnt2[i].front();
- cnt1['?'].pop(), cnt2[i].pop();
- ans.push_back(make_pair(x + 1, y + 1));
- if(cnt2[i].empty() || cnt1['?'].empty()){
- break;
- }
- }
- }
- }
- }
- if(!cnt2['?'].empty()){
- for(char i = 'a'; i <= 'z'; ++i){
- if(!cnt2['?'].empty() && !cnt1[i].empty()){
- while(!cnt2['?'].empty() && !cnt1[i].empty()){
- int y = cnt2['?'].front(), x = cnt1[i].front();
- cnt2['?'].pop(), cnt1[i].pop();
- ans.push_back(make_pair(x + 1, y + 1));
- if(cnt1[i].empty() || cnt2['?'].empty()){
- break;
- }
- }
- }
- }
- }
- queue<int> q1 = cnt1['?'];
- queue<int> q2 = cnt2['?'];
- if(!q1.empty() && !q2.empty()){
- while(!q1.empty() && !q2.empty()){
- int x = q1.front(), y = q2.front();
- q1.pop(), q2.pop();
- ans.push_back(make_pair(x + 1, y + 1));
- if(q2.empty() || q1.empty()){
- break;
- }
- }
- }
- cout << ans.size() << endl;
- for(int i = 0; i < ans.size(); ++i){
- cout << ans[i].first << " " << ans[i].second << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement