Advertisement
lalalalalalalaalalla

Untitled

Jul 7th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <iomanip>
  5. #include <queue>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <tuple>
  9. #include <iomanip>
  10. #include <stdio.h>
  11. #include <numeric>
  12. #include <map>
  13. #include <math.h>
  14. #include <bitset>
  15.  
  16. #define int long long
  17. #define ull unsigned long long
  18. #define all(a) a.begin(), a.end()
  19. #define pii pair<int, int>
  20. #define pb push_back
  21.  
  22. using namespace std;
  23.  
  24. const double PI = 3.14159265358;
  25.  
  26. long long gcd(long long a, long long b) {
  27. if (a==0) return b;
  28. if (b==0) return a;
  29. if (a>b) return gcd(a%b,b); else return gcd(b%a,a);
  30. }
  31. int prime(int p) { // 1 - простое
  32. for (int i=2;i*i<=p;i++) {
  33. if (p%i==0 && i<p) return 0;
  34. }
  35. return 1;
  36. }
  37.  
  38. double s(int x1, int y1, int x2, int y2) {
  39. return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  40. }
  41.  
  42. int t(string s) {
  43. return (s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0');
  44. }
  45.  
  46. signed main()
  47. {
  48. ios_base::sync_with_stdio(0);
  49. cin.tie(0);
  50. cout.tie(0);
  51. string s;
  52. cin >> s;
  53. int cnt = 0;
  54. string k = "", c;
  55. for (int i = 0; i < 8; i++) {
  56. while (s.size() < 4) {
  57. s = "0" + s;
  58. }
  59. sort(all(s));
  60. k = s;
  61. reverse(all(s));
  62. // cout << s << " ";
  63. s = to_string(t(s) - t(k));
  64. while (s.size() < 4) {
  65. s = "0" + s;
  66. }
  67. // cout << k << " " << s << "\n";
  68. c = s;
  69. sort(all(s));
  70. if (s == k) {
  71. cout << c << "\n" << i;
  72. break;
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement