fork(2) download
  1. /* MiraculousN*/
  2.  
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. string a,b;
  9. cin>>a>>b;
  10. int cnt=0;
  11.  
  12. if(a.length()!=b.length())
  13. cout<<"NO"<<"\n";
  14.  
  15. else
  16. {
  17. vector<char>v;
  18. set<char>st;
  19.  
  20. for(int i=0;i<a.length();i++)
  21. {
  22. if(a[i]!=b[i])
  23. {
  24. cnt++;
  25. if(cnt<=2)
  26. {
  27. v.push_back(a[i]);
  28. v.push_back(b[i]);
  29. }
  30.  
  31. }
  32.  
  33. st.insert(a[i]);
  34. }
  35.  
  36. if(cnt==2)
  37. {
  38. if(v[0]==v[3] && v[1]==v[2])
  39. cout<<"YES"<<"\n";
  40.  
  41. else
  42. cout<<"NO"<<"\n";
  43. }
  44.  
  45. else if(cnt==0)
  46. {
  47. if(st.size()<a.length())
  48. cout<<"YES"<<"\n";
  49.  
  50. else
  51. cout<<"NO"<<"\n";
  52. }
  53.  
  54. else
  55. {
  56. cout<<"NO"<<"\n";
  57. }
  58. }
  59.  
  60.  
  61.  
  62.  
  63. return 0;
  64. }
Success #stdin #stdout 0.01s 5472KB
stdin
aba
aab
stdout
YES