Korotkodul

debug

Jun 17th, 2022 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17.     for (auto x: v) cout<<x<<' ';
  18.     cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22.     for (auto x: v) cout<<x<<' ';
  23.     cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28.     for (auto x: v) cv(x);
  29.     cout<<"\n";
  30. }
  31.  
  32. void cvb(vector <bool> v){
  33.     for (bool x: v) cout<<x<<' ';
  34.     cout<<"\n";
  35. }
  36.  
  37. void cvs(vector <string>  v){
  38.     for (auto a: v){
  39.         cout<<a<<"\n";
  40.     }
  41. }
  42.  
  43.  
  44. ll to_l(string s){
  45.     ll r = 0;
  46.     reverse(s.begin(), s.end());
  47.     for (int i = 0; i < s.size(); ++i){
  48.         ll pl = (s[i] - '0') * pow(10, i);
  49.         r += pl;
  50.     }
  51.     return r;
  52. }
  53.  
  54. ll f(ll x){
  55.     cout<<"x = "<<x<<"\n";
  56.     string s; s = to_string(x);
  57.     cout<<"s = "<<s<<"\n";
  58.     int z = s.find('0');
  59.     //cout<<"z = "<<z<<"\n";
  60.     if (z != -1) s = s.substr(0, z + 1);
  61.     cout<<"s = "<<s<<"\n";
  62.     ll a,b;
  63.     //a = strtoll(s.c_str(), &endptr, 10);
  64.  
  65.     //a = strtoll(s, &end, 10);
  66.     a = to_l(s);
  67.     reverse(s.begin(), s.end());
  68.     //b = strtoll(s.c_str(), &endptr, 10);
  69.     //b = strtoll(s, &end, 10);
  70.     b = to_l(s);
  71.  
  72.     cout<<"a b = "<<a<<' '<<b<<"\n";
  73.     return min(a,b);
  74. }
  75.  
  76.  
  77.  
  78. /*
  79. 142
  80.  
  81. char* endptr = NULL;
  82. user3 = strtoll(str.c_str(), &endptr, 10);
  83. */
  84. int main()
  85. {
  86.     /*ios::sync_with_stdio(0);
  87.     cin.tie(0);
  88.     cout.tie(0);*/
  89.     ll n,k,ans=0;
  90.     cin>>n>>k;
  91.     string s = to_string(k);
  92.     reverse(s.begin(), s.end());
  93.     ll abc = k;
  94.     //ll cba = strtoll(s.c_str(), &endptr, 10);
  95.     //ll cba = strtoll(s, &end, 10);
  96.     ll cba = to_l(s);
  97.     int pow10 = log10(n);
  98.  
  99.  
  100.     if (n == k && f(n) == k){//???
  101.         cout<<1;
  102.         exit(0);
  103.     }
  104.     else if (n == k){
  105.         cout<<0;
  106.         exit(0);
  107.     }
  108.  
  109.  
  110.     if (cba >= abc && k <= n){
  111.         ans+=2;
  112.     }
  113.     for (int i = 1; i <= pow10;++i){
  114.         ll A,B;
  115.         A = abc * pow(10, i);
  116.         B = cba * pow(10, i);
  117.         if (A <= n && A >= k){
  118.             ans++;
  119.         }
  120.         if (B <= n && B >= k){
  121.             ans++;
  122.         }
  123.     }
  124.     //cout<<ans<<"\n";
  125.  
  126.     ll ch=0;
  127.     for (ll i = 1;i<=n;++i){
  128.         if (i >= k && f(i) == k){
  129.             ch++;
  130.         }
  131.     }
  132.     cout<<"ch ans = "<<ch<<' '<<ans<<"\n";
  133. }
  134.  
Add Comment
Please, Sign In to add comment