Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #include"bits/stdc++.h"
  2. using namespace std;
  3. #define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20)
  4. #define ll long long
  5. // Author
  6. // ::
  7. // ( NOBODY )
  8. // No Copyright .....You can copy and paste it without my permission...................................
  9. // !!!!!!!!!!!!!!!
  10. #define pb push_back
  11. #define N 300008
  12. int a[N],b[N],c[N];
  13. vector<pair<int,int>>vp;
  14. int main()
  15. {
  16. FAST_IO;
  17. int n;
  18. cin>>n;
  19. string s,t;
  20. cin>>s>>t;
  21. vector<int>v[30];
  22. for(int i=0;i<n;i++)
  23. {
  24. if(t[i]=='?')v[27].push_back(i);
  25. else v[t[i]-'a'].push_back(i);
  26. if(s[i]=='?')v[28].push_back(i);
  27. }
  28. for(int i=0;i<n;i++)
  29. {
  30. if(s[i]!='?')
  31. {
  32. int x=s[i]-'a';
  33.  
  34. if(v[x].size()>0)
  35. {
  36. int y=v[x].front();
  37. v[x].erase(v[x].begin(),v[x].begin()+1);
  38. vp.push_back(make_pair(i,y));
  39. }
  40. else if(v[27].size()>0)
  41. {
  42. int y=v[27].front();
  43. v[27].erase(v[27].begin(),v[27].begin()+1);
  44. vp.pb({i,y});
  45. }
  46.  
  47. }
  48. }
  49. bool boo=true;
  50. while(v[28].size()>0&&boo==true)
  51. {
  52. int x=v[28].front();
  53. for(int i=0;i<27;i++)
  54. {
  55. boo=false;
  56. if(v[i].size()>0)
  57. {
  58. boo=true;
  59. int y=v[i].front();
  60. v[i].erase(v[i].begin(),v[i].begin()+1);
  61. v[28].erase(v[28].begin(),v[28].begin()+1);
  62. vp.pb({x,y});
  63. break;
  64. }
  65. }
  66. }
  67. while(v[27].size()>0&&v[28].size()>0)
  68. {
  69. int x=v[27].front();
  70. int y=v[28].front();
  71. v[27].erase(v[27].begin(),v[27].begin()+1);
  72. v[28].erase(v[28].begin(),v[28].begin()+1);
  73. vp.push_back(make_pair(y,x));
  74. }
  75. cout<<vp.size()<<endl;
  76. for(auto c:vp)
  77. {
  78. cout<<c.first+1<<" "<<c.second+1<<endl;
  79. }
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement