Advertisement
Oslapas

Untitled

May 12th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. using namespace std;
  5. struct xy
  6. {
  7.     int x,y,nr,x1,y1;
  8. };
  9. void skaitymas(xy ma[],int &n)
  10. {
  11.     ifstream fd("kord.txt");
  12.     fd>>ma[0].x>>ma[0].y;
  13.     fd>>ma[1].x>>ma[1].y;
  14.     fd>>n;
  15.     for(int i=0;i<n;i++)
  16.     {
  17.         fd>>ma[i].nr;
  18.         for(int j=0;j<ma[i].nr;j++)
  19.         {
  20.             fd>>ma[j].x1;
  21.  
  22.         }
  23.  
  24.     }
  25.  
  26. }
  27. bool check(xy ma[],int n,int kuris)
  28. {
  29.     bool a=false;
  30.     for(int i=kuris;i<n;i++)
  31.     {
  32.         for(int j=0;j<ma[i].nr;j++)
  33.         {
  34.             if(ma[j].x1==1)
  35.             {
  36.                 ma[0].y+=1;
  37.             }
  38.             if(ma[j].x1==3)
  39.             {
  40.                 ma[0].y-=1;
  41.             }
  42.             if(ma[j].x1==4)
  43.             {
  44.                 ma[0].x-=1;
  45.             }
  46.             if(ma[j].x1==2)
  47.             {
  48.                 ma[0].x+=1;
  49.             }
  50.             cout<<ma[0].x<<" "<<ma[0].y<<" " <<ma[1].x<<"  "<<ma[1].y<<endl;
  51.             if((ma[0].x=ma[1].x)&&(ma[0].y=ma[1].y))
  52.             {
  53.                 a=true;
  54.             }
  55.         }
  56.     }
  57.     return a;
  58. }
  59. void skaiciavimas(xy ma[],int &n)
  60. {
  61.     for(int i=0;i<n;i++)
  62.     {
  63.     if(check(ma,n,i)==true)
  64.     {
  65.         cout<<"pasiektas tikslas"<<endl;
  66.     }
  67.     else
  68.     {
  69.         cout<<"sekos pabaiga"<<endl;
  70.     }
  71.     }
  72. }
  73. int main()
  74. {
  75.  xy ma[30];int n;
  76.  skaitymas(ma,n);
  77.  skaiciavimas(ma,n);
  78.  return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement