Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- char M[12][12];
- void imprimir (char M[12][12], int n, int m);
- int constru(char M[12][12],int n,int m,int&x,int &y);
- int main()
- {
- int x=0;
- int y=0;
- constru(M,12,12,x,y);
- imprimir (M,12,12) ;
- cout<<" "<<endl;
- cout<<" linha "<<y<<endl;
- cout<<" coluna "<<x<<endl;
- return 0;
- }
- int constru(char M[12][12],int n,int m,int &x, int & y)
- {
- srand ( time ( NULL ) ) ;
- int c;
- int q=0;
- int d=0;
- int C=0;
- int I=0;
- int J=0;
- int D=0;
- int Q=0;
- int F=0;
- int T=0;
- int N=0;
- for( int i =0; i < n ; i ++)
- {
- for (int j =0; j < m ; j ++)
- {
- if(i==0 || i==(n-1) || j==0 || j ==(m-1))
- {
- M[i][j]='*';
- }
- else
- {
- c =rand () % 2;
- if(c==0)
- {
- M[i][j]='*';
- }
- if(c==1)
- {
- M[i][j]='#';
- }
- }
- }
- }
- N=n-2;
- int P =rand()%2;
- if(P==0 && Q==0)
- {
- int a= rand()% N + 1;
- cout<<"ai"<<a<<endl;
- M[a][0]='I';
- M[a][1]='@';
- x=a;
- y=1;
- Q++;
- }
- if(P==1)
- {
- int a= rand()% N + 1;
- cout<<"af"<<a<<endl;
- M[a][0]='F';
- F++;
- }
- int p =rand()%2;
- if(p==0 && Q==0)
- {
- int A= rand()% N + 1;
- cout<<"Ai"<<A<<endl;
- M[0][A]='I';
- M[1][A]='@';
- x=1;
- y=A;
- }
- if(p==1 || Q>0)
- {
- int A= rand()% N + 1;
- cout<<"Af"<<A<<endl;
- M[0][A]='F';
- F++;
- T=A;
- }
- if(F==2){
- M[0][T]='I';
- M[1][T]='@';
- x=1;
- y=T;
- }
- }
- void imprimir (char M[12][12],int n,int m)
- {
- for(int i =0; i < n ; i ++)
- {
- for ( int j =0; j < m ; j ++)
- cout<< M[i][j] << " " ;
- cout<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement