Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- const int Q = 5;
- int func(int matriz1[Q][Q], int matriz2[Q][Q], int N) {
- if(N == Q) return 1;
- int i = N; // apenas para facilitar o entendimento
- int ok = 1; // ok comeca sendo true
- for(int j = 0; j < Q; j++) {
- if(matriz1[i][j] != matriz2[i][j]) {
- ok = 0; // ok recebe o valor false
- }
- }
- // variavel booleana que guarda se as matrizes sao iguais a partir da linha atual
- int ans = (ok && func(matriz1, matriz2, i+1));
- return ans;
- }
- void main() {
- int N;
- scanf("%d", &N);
- int matriz1[Q][Q], matriz2[Q][Q];
- // lendo matriz1
- for(int i = 0; i < Q; i++) {
- for(int j = 0; j < Q; j++) {
- scanf("%d", &matriz1[i][j]);
- }
- }
- // lendo matriz2
- for(int i = 0; i < Q; i++) {
- for(int j = 0; j < Q; j++) {
- scanf("%d", &matriz2[i][j]);
- }
- }
- int ans = func(matriz1, matriz2, N);
- if(ans == 1) printf("As matrizes sao iguais a partir da linha %d\n", N);
- else printf("As matrizes nao sao iguais a partir da linha %d\n", N);
- getch();
- }
- /*
- Casos de teste legais:
- 0
- 1 2 3 4 5
- 5 4 3 2 1
- 1 1 1 1 1
- 2 2 2 2 2
- 3 3 3 3 3
- 1 2 3 4 4
- 5 4 3 2 1
- 1 1 1 1 1
- 2 2 2 2 2
- 3 3 3 3 3
- Eh pra dar errado
- ///////////////////////
- 1
- 1 2 3 4 5
- 5 4 3 2 1
- 1 1 1 1 1
- 2 2 2 2 2
- 3 3 3 3 3
- 1 2 3 4 4
- 5 4 3 2 1
- 1 1 1 1 1
- 2 2 2 2 2
- 3 3 3 3 3
- Eh pra dar certo
- */
Add Comment
Please, Sign In to add comment