Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- struct xy
- {
- int x,y,nr,skaiciai[30];
- };
- void skaitymas(xy ma[],int &n)
- {
- ifstream fd("sk1.txt");
- fd>>ma[0].x>>ma[0].y;
- fd>>n;
- for(int i=0;i<n;i++)
- {
- fd>>ma[i].nr;
- for(int j=0;j<ma[i].nr;j++)
- {
- fd>>ma[i].skaiciai[j];
- }
- }
- }
- int ck(xy ma[],int n,int i,int j)
- { int a=0;
- a=ma[i].skaiciai[j];
- return a;
- }
- void sk(xy ma[],int i,int f)
- {
- for(int j=0;j<f;j++)
- {
- cout<<ma[i].skaiciai[j]<<" ";
- }
- }
- void sp(xy ma[],int i,int f)
- {
- for(int j=0;j<f;j++)
- {
- cout<<ma[i].skaiciai[j]<<" ";
- }
- }
- void skaiciavimas(xy ma[],int &n)
- {
- ifstream fd("sk1.txt");
- int a,b,c,f=0;
- ofstream fr("sk2.txt");
- for(int i=0;i<n;i++)
- {
- c=1;
- f=0;
- a=ma[0].x; b=ma[0].y;
- for(int j=0;j<ma[i].nr;j++)
- {
- if(ma[i].skaiciai[j]==1)
- {
- a+=1;
- b+=1;
- }
- if(ma[i].skaiciai[j]==2)
- {
- a+=1;
- b-=1;
- }
- if(ma[i].skaiciai[j]==3)
- {
- a-=1;
- b-=1;
- }
- if(ma[i].skaiciai[j]==4)
- {
- a-=1;
- b+=1;
- }
- f++;
- if((a==ma[0].x)&&(b==ma[0].y))
- {
- cout<<"pasiektas tikslas ";
- sk(ma,i,f); cout<<f;
- cout<<""<<endl;
- break;
- }
- if(f==ma[i].nr)
- {
- cout<<"sekos pabaiga ";
- sp(ma,i,f);
- cout<<""<< f<<" "<<a<<" "<<b<<endl;
- }
- }
- }
- }
- int main()
- {
- int n;
- xy ma[100];
- skaitymas(ma,n);
- skaiciavimas(ma,n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement