Advertisement
toffanetto_

Untitled

Nov 16th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5.  
  6. int N = 0, D = 0, L = 0, R = 0, C = 0;
  7. bool flag = false;
  8. int Matriz[11][11];
  9.  
  10. for(int i = 0; i < 10; i++){
  11. for(int j = 0; j < 10; j++){
  12. Matriz[i][j]=0;
  13. }
  14. }
  15.  
  16. cin>>N;
  17.  
  18. //NUMERO DE BARCOS
  19. for(int i = 0; i < N; i++){
  20. cin >> D >> L >> R >> C;
  21.  
  22. if(D == 0){
  23. if( (C+L-1) > 10){ //NAVIO HORIZONTAL FORA DO TABULEIRO
  24. flag = true;
  25. }
  26. else{
  27. for(int j = C; j <= C+L-1; j++)
  28. Matriz[R][j]++;
  29. }
  30. }else if(D == 1){
  31. if( (R+L-1) > 10){ //NAVIO VERTICAL FORA DO TABULEIRO
  32. flag = true;
  33. }
  34. else{
  35. for(int j = R; j <= R+L-1; j++)
  36. Matriz[j][C]++;
  37. }
  38. }
  39. }
  40.  
  41. //SE TA DEBOA, PERCORRE A MATRIZ
  42. if(flag == false){
  43. for(int i = 0; i < 10; i++)
  44. for(int j = 0; j < 10; j++){
  45. if(Matriz[i][j] > 1) //TITANIC
  46. flag = true;
  47. }
  48. }
  49.  
  50. if(flag == true)
  51. cout << "N" << endl;
  52. else
  53. cout << "Y" << endl;
  54.  
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement