Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define N 200
  5.  
  6. typedef struct {
  7.     int first_match;
  8.     int matches;
  9.     char string[N];
  10. } Eita;
  11.  
  12. int analyze(char *or, Eita *eita) {
  13.     int i, j = 0;
  14.     int flag = 0;
  15.     int result = 0;
  16.  
  17.     eita[0].matches = eita[1].matches = 0;
  18.  
  19.     for (i = 0; i < strlen(or); i++) {
  20.         if (eita[0].string[i] == or[i]) {
  21.             eita[0].matches++;
  22.  
  23.             if (!flag) {
  24.                 if (eita[1].string[i] != or[i]) {
  25.                     result = 1;
  26.                     flag = 1;
  27.                 }
  28.             }
  29.         }
  30.  
  31.         if (eita[1].string[i] == or[i]) {
  32.             eita[1].matches++;
  33.  
  34.             if (!flag) {
  35.                 if (eita[0].string[i] != or[i]) {
  36.                     result = 2;
  37.                     flag = 1;
  38.                 }
  39.             }
  40.         }
  41.     }
  42.  
  43.     return result;
  44. }
  45.  
  46. int main() {
  47.     int i, n, temp;
  48.     char original[N];
  49.     Eita eita[2];
  50.  
  51.     scanf("%d", &n);
  52.     for (i = 0; i < n; i++) {
  53.         scanf(" %[^\n]", original);
  54.         scanf(" %[^\n]", eita[0].string);
  55.         scanf(" %[^\n]", eita[1].string);
  56.  
  57.         temp = analyze(original, eita);
  58.  
  59.         printf("Instancia %d\n", i + 1);
  60.         if (eita[0].matches > eita[1].matches) {
  61.             printf("time 1\n");
  62.         } else if (eita[0].matches < eita[1].matches) {
  63.             printf("time 2\n");
  64.         } else if (!temp) {
  65.             printf("empate\n");
  66.         } else {
  67.             printf("time %d\n", temp);
  68.         }
  69.  
  70.         printf("\n");
  71.     }
  72.  
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement