Advertisement
Oslapas

Untitled

May 14th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 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,skaiciai[30];
  8. };
  9. void skaitymas(xy ma[],int &n)
  10. {
  11.     ifstream fd("sk1.txt");
  12.     fd>>ma[0].x>>ma[0].y;
  13.     fd>>n;
  14.     for(int i=0;i<n;i++)
  15.     {
  16.         fd>>ma[i].nr;
  17.         for(int j=0;j<ma[i].nr;j++)
  18.         {
  19.             fd>>ma[i].skaiciai[j];
  20.         }
  21.     }
  22. }
  23. int ck(xy ma[],int n,int i,int j)
  24. {   int a=0;
  25.     a=ma[i].skaiciai[j];
  26.     return a;
  27. }
  28. void sk(xy ma[],int i,int f)
  29. {
  30.  
  31.         for(int j=0;j<f;j++)
  32.         {
  33.            cout<<ma[i].skaiciai[j]<<" ";
  34.         }
  35.  
  36. }
  37. void sp(xy ma[],int i,int f)
  38. {
  39.  
  40.         for(int j=0;j<f;j++)
  41.         {
  42.             cout<<ma[i].skaiciai[j]<<" ";
  43.         }
  44.  
  45. }
  46. void skaiciavimas(xy ma[],int &n)
  47. {
  48.     ifstream fd("sk1.txt");
  49.     int a,b,c,f=0;
  50.     ofstream fr("sk2.txt");
  51.     for(int i=0;i<n;i++)
  52.     {
  53.         c=1;
  54.         f=0;
  55.         a=ma[0].x; b=ma[0].y;
  56.         for(int j=0;j<ma[i].nr;j++)
  57.         {
  58.                if(ma[i].skaiciai[j]==1)
  59.                {
  60.                 a+=1;
  61.                 b+=1;
  62.                }
  63.                if(ma[i].skaiciai[j]==2)
  64.                {
  65.                 a+=1;
  66.                 b-=1;
  67.                }
  68.                if(ma[i].skaiciai[j]==3)
  69.                {
  70.                 a-=1;
  71.                 b-=1;
  72.                }
  73.                if(ma[i].skaiciai[j]==4)
  74.                {
  75.                 a-=1;
  76.                 b+=1;
  77.                }
  78.                f++;
  79.                 if((a==ma[0].x)&&(b==ma[0].y))
  80.                 {
  81.                     cout<<"pasiektas tikslas ";
  82.                     sk(ma,i,f); cout<<f;
  83.                     cout<<""<<endl;
  84.                     break;
  85.                 }
  86.                if(f==ma[i].nr)
  87.                {
  88.                    cout<<"sekos pabaiga ";
  89.                    sp(ma,i,f);
  90.                    cout<<""<< f<<" "<<a<<" "<<b<<endl;
  91.                }
  92.         }
  93.  
  94.  
  95.  
  96.     }
  97. }
  98. int main()
  99. {
  100.     int n;
  101.     xy ma[100];
  102.     skaitymas(ma,n);
  103.     skaiciavimas(ma,n);
  104.     return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement