fork download
  1. #include <stdio.h>
  2. //#include <conio.h>
  3. #include <string>
  4. #include <vector>
  5. #include <math.h>
  6. #include <stack>
  7. #include <queue>
  8. #include <deque>
  9. #include <set>
  10. #include <map>
  11. #include <algorithm>
  12. #include <stdlib.h>
  13. #include <iostream>
  14. #include <sstream>
  15. using namespace std;
  16. typedef long long LL;
  17. int k;
  18. int main()
  19. {
  20. ios::sync_with_stdio(0);
  21. cin.tie(0); cout.tie(0);
  22. cin >> k;
  23. for (int i = 0; i < k; i++) {
  24. int n;
  25. string s, t;
  26. vector<pair<int, int>> res;
  27. cin >> n >> s >> t;
  28. for (int i = 0; i < n - 1; i++)
  29. if (s[i] != t[i]) {
  30. int co = 0, id = -1;
  31. for (int j = i + 1; j < n; j++)
  32. if (s[j] == t[i])
  33. co = 1, id = j;
  34. if (co) {
  35. res.push_back(pair<int, int>(id, n-1));
  36. swap(s[id], t[n-1]);
  37. res.push_back(pair<int, int>(i, n-1));
  38. swap(s[i], t[n-1]);
  39. }
  40. else
  41. {
  42. int co = 0, id = -1;
  43. for (int j = i + 1; j < n; j++)
  44. if (t[j] == t[i])
  45. co = 1, id = j;
  46. if (co) {
  47. res.push_back(pair<int, int>(i, id));
  48. swap(s[i], t[id]);
  49. }
  50. else
  51. break;
  52. }
  53. }
  54. if (s == t) {
  55. cout << "Yes\n" << res.size() << "\n";
  56. for (int i = 0; i < res.size(); i++)
  57. cout << res[i].first +1<< " " << res[i].second +1<< "\n";
  58. }
  59. else
  60. cout << "No\n";
  61. }
  62. //_getch();
  63. return 0;
  64. }
Success #stdin #stdout 0s 4364KB
stdin
1
6
aabbbb
dddddd
stdout
Yes
4
1 6
2 5
3 4
5 6