fork download
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include <stdlib.h>
  6. #include <time.h>
  7.  
  8. struct time {
  9. char caracter;
  10. char nome[30];
  11. int continente;
  12. int qtde_partidas;
  13. int gols_a_favor;
  14. int gols_contra;
  15. int saldo_gols;
  16. };
  17. typedef struct time Time;
  18.  
  19. struct partida{
  20. int codigo;
  21. char time1;
  22. char time2;
  23. int gols_time1;
  24. int gols_time2;
  25. };
  26. typedef struct partida Partida;
  27.  
  28. void gols_contraa (char a, Time VetorTimes[], int n, int b);
  29. void gols_aa_favor (char a, Time VetorTimes[], int n, int b);
  30. void saldo_gols (Time VetorTimes[], int n);
  31. void ReceberTimes(Time VetorTimes[], int tamanho);
  32. void ReceberPartidas(Partida vetorPartidas[], int tam_part, Time VetorTimes[], int tam_times);
  33.  
  34. void ReceberTimes(Time VetorTimes[], int tamanho){
  35. for (int j = 0; j < tamanho; j++)
  36. {
  37. VetorTimes[j].gols_a_favor = 0;
  38. VetorTimes[j].gols_contra = 0;
  39. VetorTimes[j].saldo_gols = 0;
  40. VetorTimes[j].qtde_partidas = 0;
  41. }
  42.  
  43. for(int i = 0; i < tamanho; i++){
  44. scanf(" %c",&VetorTimes[i].caracter);
  45. gets(VetorTimes[i].nome);
  46. scanf("%d", &VetorTimes[i].continente);
  47. }
  48.  
  49. }
  50. void ReceberPartidas(Partida vetorPartidas[], int tam_part, Time VetorTimes[], int tam_times){
  51.  
  52. for(int j = 0; j < tam_part; j++){
  53.  
  54. scanf("%d", &vetorPartidas[j].codigo); //código partida
  55. scanf(" %c", &vetorPartidas[j].time1); //caracter time 1
  56. scanf(" %c", &vetorPartidas[j].time2); //caracter time 2
  57. scanf("%d", &vetorPartidas[j].gols_time1); //gols time1
  58. scanf("%d", &vetorPartidas[j].gols_time2); //gols time2
  59. gols_aa_favor(vetorPartidas[j].time1, VetorTimes, tam_times, vetorPartidas[j].gols_time1); //adicionar gols ao time 1
  60. gols_contraa(vetorPartidas[j].time2, VetorTimes, tam_times, vetorPartidas[j].gols_time1); //gols tomados pelo time 2
  61. gols_aa_favor(vetorPartidas[j].time2, VetorTimes, tam_times, vetorPartidas[j].gols_time2); // adicionar gols ao time 2
  62. gols_contraa(vetorPartidas[j].time1, VetorTimes, tam_times, vetorPartidas[j].gols_time2); // gols tomado pelo time 1
  63. }
  64.  
  65. }
  66. void MelhorSaldoGols(Time VetorTimes[], int tamanho){
  67. Time melhor = VetorTimes[0];
  68. for(int i = 1; i < tamanho; i++){
  69. if(VetorTimes[i].saldo_gols > melhor.saldo_gols){
  70. melhor.caracter = VetorTimes[i].caracter;
  71. }
  72. }
  73. printf("%c", melhor.caracter);
  74. }
  75. Time PiorSaldoGols(Time VetorTimes[], int tamanho){
  76. Time pior = VetorTimes[0];
  77. for(int i = 1; i < tamanho; i++){
  78. if(VetorTimes[i].saldo_gols < pior.saldo_gols){
  79. pior.caracter = VetorTimes[i].caracter;
  80. }
  81. }
  82. printf("%c", pior.caracter);
  83. }
  84. Time MelhorClassificadoContinente(Partida VetorPartida[], int tam_part, Time VetorTimes[], int tam_times, int continente){
  85. Time t;
  86. return t;
  87. }
  88. void gols_aa_favor (char a, Time VetorTimes[], int n, int b){
  89. for(int u = 0; u < n; u++){
  90. if(VetorTimes[u].caracter == a){
  91. VetorTimes[u].gols_a_favor = VetorTimes[u].gols_a_favor + b;
  92. }
  93. }
  94. }
  95. void gols_contraa (char a, Time VetorTimes[], int n, int b){
  96. for(int u = 0; u < n; u++){
  97. if(VetorTimes[u].caracter == a){
  98. VetorTimes[u].gols_contra = VetorTimes[u].gols_contra + b;
  99. }
  100. }
  101. }
  102.  
  103. void saldo_gols (Time VetorTimes[], int n){
  104. for(int u = 0; u < n; u++){
  105. VetorTimes[u].saldo_gols = VetorTimes[u].gols_a_favor - VetorTimes[u].gols_contra; //cálculo saldo de gols.
  106. }
  107. }
  108.  
  109. int main(){
  110. Time paises[16];
  111. Partida part[15];
  112. int n, k, cod, t1, t2;
  113. char nm, melhor;
  114. n = k = cod = t1 = t2 = 0;
  115.  
  116. scanf("%d", &n);
  117. ReceberTimes(paises, n);
  118.  
  119. scanf("%d", &k);
  120. ReceberPartidas(part, k, paises, n);
  121.  
  122. saldo_gols(paises, n);
  123.  
  124. MelhorSaldoGols(paises, n);
  125. printf("\n");
  126. PiorSaldoGols(paises, n);
  127.  
  128.  
  129. return 0;
  130. }
Success #stdin #stdout 0.01s 5324KB
stdin
8

A

BRASIL

1

B

FRANCA

2

C

JAPAO

4

D

SENEGAL

3

E

AUSTRALIA

5

F

ARGENTINA

1

G

ALEMANHA

2

H

INGLATERRA

2

7

1

A

B

3

1

2

C

D

2

3

3

E

F

7

1

4

G

H

0

1

5

A

D

2

3

6

E

H

3

1

7

D

E

1

2
stdout
A
A