Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. char M[12][12];
  7. void imprimir (char M[12][12], int n, int m);
  8. int constru(char M[12][12],int n,int m,int&x,int &y);
  9.  
  10. int main()
  11. {
  12. int x=0;
  13. int y=0;
  14. constru(M,12,12,x,y);
  15. imprimir (M,12,12) ;
  16. cout<<" "<<endl;
  17. cout<<" linha "<<y<<endl;
  18. cout<<" coluna "<<x<<endl;
  19.  
  20. return 0;
  21. }
  22.  
  23. int constru(char M[12][12],int n,int m,int &x, int & y)
  24. {
  25.  
  26. srand ( time ( NULL ) ) ;
  27. int c;
  28. int q=0;
  29. int d=0;
  30. int C=0;
  31. int I=0;
  32. int J=0;
  33. int D=0;
  34. int Q=0;
  35. int F=0;
  36. int T=0;
  37. int N=0;
  38.  
  39. for( int i =0; i < n ; i ++)
  40. {
  41. for (int j =0; j < m ; j ++)
  42. {
  43. if(i==0 || i==(n-1) || j==0 || j ==(m-1))
  44. {
  45. M[i][j]='*';
  46. }
  47. else
  48. {
  49.  
  50. c =rand () % 2;
  51. if(c==0)
  52. {
  53. M[i][j]='*';
  54. }
  55. if(c==1)
  56. {
  57.  
  58.  
  59. M[i][j]='#';
  60.  
  61. }
  62. }
  63. }
  64. }
  65.  
  66. N=n-2;
  67.  
  68. int P =rand()%2;
  69. if(P==0 && Q==0)
  70. {
  71. int a= rand()% N + 1;
  72. cout<<"ai"<<a<<endl;
  73. M[a][0]='I';
  74. M[a][1]='@';
  75. x=a;
  76. y=1;
  77. Q++;
  78. }
  79. if(P==1)
  80. {
  81. int a= rand()% N + 1;
  82. cout<<"af"<<a<<endl;
  83. M[a][0]='F';
  84. F++;
  85. }
  86.  
  87.  
  88.  
  89.  
  90. int p =rand()%2;
  91. if(p==0 && Q==0)
  92. {
  93. int A= rand()% N + 1;
  94. cout<<"Ai"<<A<<endl;
  95. M[0][A]='I';
  96. M[1][A]='@';
  97. x=1;
  98. y=A;
  99.  
  100. }
  101. if(p==1 || Q>0)
  102. {
  103. int A= rand()% N + 1;
  104. cout<<"Af"<<A<<endl;
  105. M[0][A]='F';
  106. F++;
  107. T=A;
  108. }
  109. if(F==2){
  110. M[0][T]='I';
  111. M[1][T]='@';
  112. x=1;
  113. y=T;
  114.  
  115. }
  116. }
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129. void imprimir (char M[12][12],int n,int m)
  130. {
  131. for(int i =0; i < n ; i ++)
  132. {
  133. for ( int j =0; j < m ; j ++)
  134.  
  135. cout<< M[i][j] << " " ;
  136.  
  137. cout<<endl;
  138.  
  139.  
  140. }
  141.  
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement