Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- typedef struct TIME
- {
- char nome;
- int pts;
- int sg;
- int nv;
- int gf;
- } t;
- int descobretime(char x)
- {
- return x-'A';
- }
- int main ()
- {
- t times[6]= {0,0,0,0,0};
- times[0].nome = 'A';
- times[1].nome = 'B';
- times[2].nome = 'C';
- times[3].nome = 'D';
- times[4].nome = 'E';
- times[5].nome = 'F';
- char t1, t2;
- int i, x, y, m,n, golsofrido[6]= {}, max=-1, pos;
- FILE *fp, *p;
- fp = fopen("resultados.txt", "r");
- p = fopen("tabela.txt", "w");
- if(fp == NULL)
- {
- printf("Erro na abertura do arquivo\n");
- exit(1);
- }
- for(i=0;i<30;i++)
- {
- fscanf(fp, "%c\t%d\t%c\t%d\n",&t1, &x, &t2, &y);
- m = descobretime (t1);
- n = descobretime(t2);
- if(x==y)
- {
- times[m].pts+=1;
- times[n].pts+=1;
- times[m].gf+=x;
- times[n].gf+=y;
- golsofrido[m]+=y;
- golsofrido[n]+=x;
- }
- if (x>y)
- {
- times[m].pts+=3;
- times[n].pts+=0;
- times[m].gf+=x;
- times[n].gf+=y;
- golsofrido[m]+=y;
- golsofrido[n]+=x;
- times[m].nv+=1;
- }
- if (y>x)
- {
- times[m].pts+=0;
- times[n].pts+=3;
- times[m].gf+=x;
- times[n].gf+=y;
- golsofrido[m]+=y;
- golsofrido[n]+=x;
- times[n].nv+=1;
- }
- }
- for(i=0; i<6; i++)
- {
- times[i].sg = times[i].gf - golsofrido[i];
- if(times[i].pts > max)
- {
- max = times[i].pts; pos=i;
- }
- }
- printf("TIME PONTOS SALDO VITORIAS GOLS\n");
- fprintf(p,"TIME PONTOS SALDO VITORIAS GOLS\n");
- for(i=0;i<6;i++){
- 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);
- 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);
- }
- printf("O time campeao e o %c com %d pontos", times[pos].nome, times[pos].pts);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement