Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<vector>
- #include<queue>
- using namespace std;
- int main()
- {
- int s,e;
- cin>>s>>e;
- int razlika=e-s;
- int palindromi[e-s+1];
- int brojac=0;
- for(int i=1;i<=(e-s);i++)
- {
- int e_palindrom = 1;
- vector<int> v;
- int tmp = i;
- while(tmp > 0) {
- v.push_back(tmp % 10);
- tmp /= 10;
- }
- int a = 0, b = v.size() - 1;
- while(a < b) {
- if(v[a] != v[b]) {
- e_palindrom = 0;
- break;
- }
- a += 1;
- b -= 1;
- }
- if(e_palindrom==1)
- {
- palindromi[brojac]=i;
- brojac++;
- }
- }
- queue<int>q;
- q.push(s);
- q.push(0);
- int visited[e+1];
- for(int i=0;i<e+1;i++)
- {
- visited[i]=false;
- }
- while(!q.empty())
- {
- int ci=q.front();
- q.pop();
- int cekor=q.front();
- q.pop();
- if(ci==e)
- {
- cout<<cekor<<endl;
- return 0;
- }
- for(int k=0;k<brojac;k++)
- {
- if(palindromi[k]<ci)
- {
- int ti=ci+palindromi[k];
- if(ti<=e && !visited[ti])
- {
- q.push(ti);
- visited[ti]=true;
- q.push(cekor+1);
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement