tungggg

soganhoanhao

Feb 1st, 2022
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. // ITPTIT - Mai la anh em
  4. // bool solve(string s){
  5. //     if(s.size()==1) return true;
  6. //     for(int i=0;i<s.size();i++){
  7. //         if (s[i]!='0'&&s[i]!='6' && s[i]!='8') {
  8. //             return false;
  9. //         }    
  10. //     }
  11. //     return true;
  12. // }
  13. // bool check (int n){
  14. //     string s= to_string (n);
  15. //      if(s.size()==1) return true;
  16. //     if(s[0]==s[s.size()-1]) return true;
  17. //     else return false;
  18. // }
  19. bool check (string s){
  20.     if(s[0]==s[s.size()-1]) return true;
  21.     return false;
  22. }
  23. string sum_big(string a, string b){
  24.     if(a.size()>b.size()){
  25.         b=string ( a.size()-b.size(),'0')+b;
  26.     }
  27.     else if( b.size()>a.size()) {
  28.         a=string (b.size()-a.size(),'0')+a;
  29.     }
  30.     int remain=0;
  31.     for(int i=a.size()-1;i>=0;i--){
  32.         int current = (a[i]-'0') + (b[i]-'0') + remain;
  33.         a[i]=(current%10)+'0';
  34.         remain=current /10;
  35.     }
  36.     if(remain!=0){
  37.         return (char) (remain+'0')+a;
  38.     }
  39.     else return a;
  40. }
  41. int main() {
  42.     // Your code goes here
  43.     string a, b;
  44.     cin>>a>>b;
  45.     if(a.size()==b.size()){
  46.         cout<<(b[0]-'0')-(a[0]-'0')+1;
  47.     }
  48.     else {
  49.         int c=0;
  50.         while(a!=b){
  51.             if(check(a)){
  52.                 c++;
  53.             }
  54.             a=sum_big(a,"1");
  55.        
  56.         }
  57.         if(check(a)) c++;
  58.         cout<<c;
  59.     }
  60.     return 0;
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment