fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7. string a,b;
  8. cin >> a >> b;
  9. int h = 0;
  10. map<pair<char,char>,int> pairs;
  11. bool sol_found = false;
  12. int first_idx,sec_idx;
  13. vector<int> sec(26,-1);
  14. vector<int> fir(26,-1);
  15. for(int i = 0 ; i < a.size() ; i++){
  16. if(a[i] != b[i]){
  17. //cout << a[i] << " "<< b[i] << " " << pairs[{b[i],a[i]}] << endl;
  18. if(pairs[{b[i],a[i]}]){
  19. sol_found = true;
  20. first_idx = pairs[{b[i],a[i]}];
  21. sec_idx = i+1;
  22. }
  23. pairs[{a[i],b[i]}] = i+1;
  24. h++;
  25. sec[b[i] - 'a'] = i+1;
  26. fir[a[i] - 'a'] = i+1;
  27. }
  28. }
  29. //cout << h << " " << sol_found << endl;
  30. if(sol_found){
  31. cout << h-2 << endl;
  32. //cout << first_idx << " " << sec_idx << endl;
  33. return 0;
  34. }
  35. for(int i = 0 ; i < 26 ; i++){
  36. //cout << fir[i] << " " << sec[i] << endl;
  37. if(fir[i] != -1 && sec[i] != -1){
  38. if(fir[i] != sec[i]){
  39. cout << h - 1 << endl;
  40. cout << fir[i] << " " << sec[i] << endl;
  41. return 0;
  42. }else{
  43. cout << h-1 << endl;
  44. cout << -1 << " " << -1 << endl;
  45. return 0;
  46. }
  47. }
  48. }
  49. cout << h << endl;
  50. cout << -1 << " " << -1 << endl;
  51. return 0;
  52. }
Success #stdin #stdout 0.01s 5336KB
stdin
6
wookie
cookie
stdout
1
-1 -1