Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. typedef struct TIME
  6. {
  7. char nome;
  8. int pts;
  9. int sg;
  10. int nv;
  11. int gf;
  12. } t;
  13. int descobretime(char x)
  14. {
  15. return x-'A';
  16. }
  17. int main ()
  18. {
  19. t times[6]= {0,0,0,0,0};
  20. times[0].nome = 'A';
  21. times[1].nome = 'B';
  22. times[2].nome = 'C';
  23. times[3].nome = 'D';
  24. times[4].nome = 'E';
  25. times[5].nome = 'F';
  26. char t1, t2;
  27. int i, x, y, m,n, golsofrido[6]= {}, max=-1, pos;
  28. FILE *fp, *p;
  29. fp = fopen("resultados.txt", "r");
  30. p = fopen("tabela.txt", "w");
  31. if(fp == NULL)
  32. {
  33. printf("Erro na abertura do arquivo\n");
  34. exit(1);
  35. }
  36. for(i=0;i<30;i++)
  37. {
  38. fscanf(fp, "%c\t%d\t%c\t%d\n",&t1, &x, &t2, &y);
  39. m = descobretime (t1);
  40. n = descobretime(t2);
  41. if(x==y)
  42. {
  43. times[m].pts+=1;
  44. times[n].pts+=1;
  45. times[m].gf+=x;
  46. times[n].gf+=y;
  47. golsofrido[m]+=y;
  48. golsofrido[n]+=x;
  49. }
  50. if (x>y)
  51. {
  52. times[m].pts+=3;
  53. times[n].pts+=0;
  54. times[m].gf+=x;
  55. times[n].gf+=y;
  56. golsofrido[m]+=y;
  57. golsofrido[n]+=x;
  58. times[m].nv+=1;
  59. }
  60. if (y>x)
  61. {
  62. times[m].pts+=0;
  63. times[n].pts+=3;
  64. times[m].gf+=x;
  65. times[n].gf+=y;
  66. golsofrido[m]+=y;
  67. golsofrido[n]+=x;
  68. times[n].nv+=1;
  69. }
  70. }
  71. for(i=0; i<6; i++)
  72. {
  73. times[i].sg = times[i].gf - golsofrido[i];
  74. if(times[i].pts > max)
  75. {
  76. max = times[i].pts; pos=i;
  77. }
  78. }
  79. printf("TIME PONTOS SALDO VITORIAS GOLS\n");
  80. fprintf(p,"TIME PONTOS SALDO VITORIAS GOLS\n");
  81. for(i=0;i<6;i++){
  82. printf("%c\t%d\t%d\t%d\t%d\n", times[i].nome, times[i].pts, times[i].sg, times[i].nv, times[i].gf);
  83. fprintf(p,"%c\t%d\t%d\t%d\t%d\n", times[i].nome, times[i].pts,times[i].sg, times[i].nv, times[i].gf);
  84. }
  85. printf("O time campeao e o %c com %d pontos", times[pos].nome, times[pos].pts);
  86.  
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement