Joao_Joao

Questão 274 Lista de Exercícios IFPB

Mar 18th, 2024 (edited)
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. const int Q = 5;
  4.  
  5. int func(int matriz1[Q][Q], int matriz2[Q][Q], int N) {
  6.     if(N == Q) return 1;
  7.     int i = N; // apenas para facilitar o entendimento
  8.     int ok = 1; // ok comeca sendo true
  9.     for(int j = 0; j < Q; j++) {
  10.         if(matriz1[i][j] != matriz2[i][j]) {
  11.             ok = 0; // ok recebe o valor false
  12.         }
  13.     }
  14.     // variavel booleana que guarda se as matrizes sao iguais a partir da linha atual
  15.     int ans = (ok && func(matriz1, matriz2, i+1));
  16.     return ans;
  17. }
  18.  
  19. void main() {
  20.     int N;
  21.     scanf("%d", &N);
  22.    
  23.     int matriz1[Q][Q], matriz2[Q][Q];
  24.    
  25.     // lendo matriz1
  26.     for(int i = 0; i < Q; i++) {
  27.         for(int j = 0; j < Q; j++) {
  28.             scanf("%d", &matriz1[i][j]);
  29.         }
  30.     }
  31.     // lendo matriz2
  32.     for(int i = 0; i < Q; i++) {
  33.         for(int j = 0; j < Q; j++) {
  34.             scanf("%d", &matriz2[i][j]);
  35.         }
  36.     }
  37.     int ans = func(matriz1, matriz2, N);
  38.     if(ans == 1) printf("As matrizes sao iguais a partir da linha %d\n", N);
  39.     else printf("As matrizes nao sao iguais a partir da linha %d\n", N);
  40.    
  41.     getch();
  42. }
  43.  
  44. /*
  45. Casos de teste legais:
  46. 0
  47. 1 2 3 4 5
  48. 5 4 3 2 1
  49. 1 1 1 1 1
  50. 2 2 2 2 2
  51. 3 3 3 3 3
  52. 1 2 3 4 4
  53. 5 4 3 2 1
  54. 1 1 1 1 1
  55. 2 2 2 2 2
  56. 3 3 3 3 3
  57. Eh pra dar errado
  58. ///////////////////////
  59. 1
  60. 1 2 3 4 5
  61. 5 4 3 2 1
  62. 1 1 1 1 1
  63. 2 2 2 2 2
  64. 3 3 3 3 3
  65. 1 2 3 4 4
  66. 5 4 3 2 1
  67. 1 1 1 1 1
  68. 2 2 2 2 2
  69. 3 3 3 3 3
  70. Eh pra dar certo
  71. */
  72.  
Add Comment
Please, Sign In to add comment