Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- using namespace std;
- int main()
- {
- int minuti;
- int saati;
- int minuti1;
- int saati1;
- cin>>saati>>minuti>>saati1>>minuti1;
- queue<int>q;
- int niza[]{-1,1,0,0};
- int niza1[]{0,0,-1,1};
- bool visited[24][60];
- for(int m=0; m<24; m++){
- for(int n=0; n<60; n++){
- visited[m][n]=false;
- }
- }
- q.push(saati);
- q.push(minuti);
- q.push(0);
- while(!q.empty()){
- int cs=q.front();
- q.pop();
- int cm=q.front();
- q.pop();
- int pritisoci=q.front();
- q.pop();
- if((cs==saati1)and(cm==minuti1)){
- cout<<pritisoci;
- return 0;
- }
- for(int h=0; h<4; h++){
- int ts=cs+niza[h];
- int tm=cm+niza1[h];
- if(tm==-1){
- tm=59;
- ts-=1;
- }
- if(tm==60){
- tm=0;
- ts+=1;
- }
- if(ts==24){
- ts=0;
- }
- if(ts==-1){
- ts=23;
- }
- if(visited[ts][tm]==false){
- q.push(ts);
- q.push(tm);
- q.push(pritisoci+1);
- visited[ts][tm]=true;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement