fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define FOR(i, a, b) for (int i = a; i <= b; ++i)
  4. #define FORD(i, a, b) for (int i = a; i >= b; --i)
  5. #define ll long long
  6.  
  7. using namespace std;
  8.  
  9. string s, t;
  10.  
  11. void nhap() {
  12. cin >> s >> t;
  13. }
  14.  
  15. bool is_friends(string a, string b) {
  16. while (a.size() > 1 && a[0] == '0') a.erase(0, 1);
  17. while (b.size() > 1 && b[0] == '0') b.erase(0, 1);
  18. sort(a.begin(), a.end());
  19. sort(b.begin(), b.end());
  20. a.erase(unique(a.begin(), a.end()), a.end());
  21. b.erase(unique(b.begin(), b.end()), b.end());
  22. return (a == b);
  23. }
  24.  
  25. bool can_transform(string s, string t) {
  26. int n = s.size();
  27. FOR(i, 0, n - 2) {
  28. if (s[i] > '0' && s[i + 1] < '9') {
  29. string x = s;
  30. x[i]--; x[i + 1]++;
  31. if (x[0] != '0' && is_friends(x, t)) return 1;
  32. }
  33. if (s[i] < '9' && s[i + 1] > '0') {
  34. string x = s;
  35. x[i]++; x[i + 1]--;
  36. if (x[0] != '0' && is_friends(x, t)) return 1;
  37. }
  38. }
  39. return 0;
  40. }
  41.  
  42. void giai() {
  43. if (is_friends(s, t)) cout << "friends";
  44. else if (can_transform(s, t) || can_transform(t, s)) cout << "almost friends";
  45. else cout << "nothing";
  46. }
  47.  
  48. int main() {
  49. ios_base::sync_with_stdio(0);
  50. cin.tie(0); cout.tie(0);
  51.  
  52. #define name "digits"
  53.  
  54. if (fopen(name".inp", "r")) {
  55. freopen(name".inp", "r", stdin);
  56. freopen(name".out", "w", stdout);
  57. }
  58.  
  59. nhap();
  60. giai();
  61.  
  62. return 0;
  63. }
  64.  
Success #stdin #stdout 0s 5300KB
stdin
Standard input is empty
stdout
friends