Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include"bits/stdc++.h"
- using namespace std;
- #define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20)
- #define ll long long
- // Author
- // ::
- // ( NOBODY )
- // No Copyright .....You can copy and paste it without my permission...................................
- // !!!!!!!!!!!!!!!
- #define pb push_back
- #define N 300008
- int a[N],b[N],c[N];
- vector<pair<int,int>>vp;
- int main()
- {
- FAST_IO;
- int n;
- cin>>n;
- string s,t;
- cin>>s>>t;
- vector<int>v[30];
- for(int i=0;i<n;i++)
- {
- if(t[i]=='?')v[27].push_back(i);
- else v[t[i]-'a'].push_back(i);
- if(s[i]=='?')v[28].push_back(i);
- }
- for(int i=0;i<n;i++)
- {
- if(s[i]!='?')
- {
- int x=s[i]-'a';
- if(v[x].size()>0)
- {
- int y=v[x].front();
- v[x].erase(v[x].begin(),v[x].begin()+1);
- vp.push_back(make_pair(i,y));
- }
- else if(v[27].size()>0)
- {
- int y=v[27].front();
- v[27].erase(v[27].begin(),v[27].begin()+1);
- vp.pb({i,y});
- }
- }
- }
- bool boo=true;
- while(v[28].size()>0&&boo==true)
- {
- int x=v[28].front();
- for(int i=0;i<27;i++)
- {
- boo=false;
- if(v[i].size()>0)
- {
- boo=true;
- int y=v[i].front();
- v[i].erase(v[i].begin(),v[i].begin()+1);
- v[28].erase(v[28].begin(),v[28].begin()+1);
- vp.pb({x,y});
- break;
- }
- }
- }
- while(v[27].size()>0&&v[28].size()>0)
- {
- int x=v[27].front();
- int y=v[28].front();
- v[27].erase(v[27].begin(),v[27].begin()+1);
- v[28].erase(v[28].begin(),v[28].begin()+1);
- vp.push_back(make_pair(y,x));
- }
- cout<<vp.size()<<endl;
- for(auto c:vp)
- {
- cout<<c.first+1<<" "<<c.second+1<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement