Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // ITPTIT - Mai la anh em
- // bool solve(string s){
- // if(s.size()==1) return true;
- // for(int i=0;i<s.size();i++){
- // if (s[i]!='0'&&s[i]!='6' && s[i]!='8') {
- // return false;
- // }
- // }
- // return true;
- // }
- // bool check (int n){
- // string s= to_string (n);
- // if(s.size()==1) return true;
- // if(s[0]==s[s.size()-1]) return true;
- // else return false;
- // }
- bool check (string s){
- if(s[0]==s[s.size()-1]) return true;
- return false;
- }
- string sum_big(string a, string b){
- if(a.size()>b.size()){
- b=string ( a.size()-b.size(),'0')+b;
- }
- else if( b.size()>a.size()) {
- a=string (b.size()-a.size(),'0')+a;
- }
- int remain=0;
- for(int i=a.size()-1;i>=0;i--){
- int current = (a[i]-'0') + (b[i]-'0') + remain;
- a[i]=(current%10)+'0';
- remain=current /10;
- }
- if(remain!=0){
- return (char) (remain+'0')+a;
- }
- else return a;
- }
- int main() {
- // Your code goes here
- string a, b;
- cin>>a>>b;
- if(a.size()==b.size()){
- cout<<(b[0]-'0')-(a[0]-'0')+1;
- }
- else {
- int c=0;
- while(a!=b){
- if(check(a)){
- c++;
- }
- a=sum_big(a,"1");
- }
- if(check(a)) c++;
- cout<<c;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment