Posted: Fri Sep 17, 2004 9:07 pm
MatH
math
should be treated as same.
Hope you got it.
math
should be treated as same.
Hope you got it.
Code: Select all
2
blah
2
A
a
2
A#1@1#a
a#1@1#A
yada
2
a
A
2
A#1@1#a
a#1@1#A
Code: Select all
blah
1) A 2p, 2g (0-2-0), 0gd (2-2)
2) a 2p, 2g (0-2-0), 0gd (2-2)
yada
1) a 2p, 2g (0-2-0), 0gd (2-2)
2) A 2p, 2g (0-2-0), 0gd (2-2)
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#define lim 40
#define lim_2 39
#define tour 102
#define wor 72
int main()
{
/* In the struct below, result[0] are the wins, result[1] are the ties, result[2] are the losses; goals[0] are the goals scored and goals[1] are the goals against. */
struct _team
{
char name[lim];
int points, result[3], games, goals[2];
}team[lim];
int n_tournaments, i, j, k, l, games, teams, score1, score2, aux;
char *team1, *team2, n_team[lim], word[wor], tournament[tour];
scanf("%d", &n_tournaments);
getc(stdin);
for(i=0; i < n_tournaments; ++i)
{
for(j=0; j < lim; ++j)
{
team[j].games = 0;
team[j].points = 0;
for(k=0; k < 2; k++)
team[j].goals[k] = 0;
for(k=0; k < 3; ++k)
team[j].result[k] = 0;
}
aux = 0;
fgets(tournament, tour, stdin);
scanf("%d", &teams);
getc(stdin);
for(j=0; j < teams; ++j)
{
fgets(n_team, lim, stdin);
team1 = strtok(n_team, "\n");
strcpy(team[j].name, team1);
}
scanf("%d", &games);
getc(stdin);
for(j=0; j < games; ++j)
{
fgets(word, wor, stdin);
team1 = strtok(word, "#");
score1 = atoi(strtok(NULL, "@"));
score2 = atoi(strtok(NULL, "#"));
team2 = strtok(NULL, "\n");
if(strcasecmp(team1, team2) != 0)
{
for(k=0; k < teams; ++k)
{
if(strcasecmp(team[k].name, team1) == 0)
break;
}
for(l=0; l < teams; ++l)
{
if(strcasecmp(team[l].name, team2) == 0)
break;
}
team[l].games++;
team[k].games++;
team[l].goals[1] += score1;
team[l].goals[0] += score2;
team[k].goals[0] += score1;
team[k].goals[1] += score2;
if(score1 < score2)
{
team[l].points += 3; /* Lose 1 and Win 2! */
team[k].result[2]++;
team[l].result[0]++;
}
else if(score1 > score2)
{
team[k].points += 3; /* Win 1 and Lose 2! */
team[l].result[2]++;
team[k].result[0]++;
}
else
{
team[k].points++; /* Tie between 1 */
team[l].points++; /* and 2! */
team[k].result[1]++;
team[l].result[1]++;
}
}
}
/* Calculates for to print OUTPUT */
printf("%s", tournament);
for(k=0; k < (teams - 1); ++k)
{
for(l=k; l < teams; ++l)
{
/* Most points */
if(team[k].points < team[l].points)
{
team[lim_2] = team[k];
team[k] = team[l];
team[l] = team[lim_2];
}
/* Most wins */
else if(team[k].points == team[l].points && team[k].result[0] < team[l].result[0])
{
team[lim_2] = team[k];
team[k] = team[l];
team[l] = team[lim_2];
}
/* Most goals difference */
else if(team[k].points == team[l].points && team[k].result[0] == team[l].result[0] && (team[k].goals[0] - team[k].goals[1]) < (team[l].goals[0] - team[l].goals[1]))
{
team[lim_2] = team[k];
team[k] = team[l];
team[l] = team[lim_2];
}
/* Most goals scored */
else if(team[k].points == team[l].points && team[k].result[0] == team[l].result[0] && (team[k].goals[0] - team[k].goals[1]) == (team[l].goals[0] - team[l].goals[1]) && team[k].goals[0] < team[k].goals[0])
{
team[lim_2] = team[k];
team[k] = team[l];
team[l] = team[lim_2];
}
/* Less games played */
else if(team[k].points == team[l].points && team[k].result[0] == team[l].result[0] && (team[k].goals[0] - team[k].goals[1]) == (team[l].goals[0] - team[l].goals[1]) && team[k].goals[0] == team[l].goals[0] && team[k].games > team[l].games)
{
team[lim_2] = team[k];
team[k] = team[l];
team[l] = team[lim_2];
}
/* Case two teams are tied, the list is appears in lexicographic order. (OBS: Use of the function strcasecmp) */
else if(team[k].points == team[l].points && team[k].result[0] == team[l].result[0] && (team[k].goals[0] - team[k].goals[1]) == (team[l].goals[0] - team[l].goals[1]) && team[k].goals[0] == team[l].goals[0] && team[k].games == team[l].games && strcasecmp(team[k].name, team[l].name) >= 0 )//&& strlen(team[k].name)<strlen(team[l].name))
{
team[lim_2] = team[k];
team[k] = team[l];
team[l] = team[lim_2];
}
}
}
aux++;
/* Printing OUTPUT */
for(j=0; j < teams; ++j)
{
printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", aux, team[j].name, team[j].points, team[j].games, team[j].result[0], team[j].result[1], team[j].result[2], (team[j].goals[0] - team[j].goals[1]), team[j].goals[0], team[j].goals[1]);
aux++;
}
if(i < (n_tournaments - 1))
printf("\n");
}
return 0;
}
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#define lim 41
#define lim_2 40
#define tour 102
#define wor 72
int main()
{
/* In the struct below, result[0] are the wins, result[1] are the ties, result[2] are the losses; goals[0] are the goals scored and goals[1] are the goals against. */
struct _team
{
char name[lim];
int points, result[3], games, goals[2];
}team[lim];
int n_tournaments, i, j, k, l,m, games, teams, score1, score2, aux;
char *team1, *team2, n_team[lim], word[wor], tournament[tour];
char previous[40];
scanf("%d", &n_tournaments);
getc(stdin);
for(i=0; i < n_tournaments; ++i)
{
for(j=0; j < lim; ++j)
{
team[j].games = 0;
team[j].points = 0;
for(k=0; k < 2; k++)
team[j].goals[k] = 0;
for(k=0; k < 3; ++k)
team[j].result[k] = 0;
}
aux = 0;
fgets(tournament, tour, stdin);
scanf("%d", &teams);
getc(stdin);
for(j=0; j < teams; ++j)
{
fgets(n_team, lim, stdin);
team1 = strtok(n_team, "\n");
strcpy(team[j].name, team1);
}
scanf("%d", &games);
getc(stdin);
for(j=0; j < games; ++j)
{
fgets(word, wor, stdin);
team1 = strtok(word, "#");
score1 = atoi(strtok(NULL, "@"));
score2 = atoi(strtok(NULL, "#"));
team2 = strtok(NULL, "\n");
if(strcasecmp(team1, team2) != 0)
{
for(k=0; k < teams; ++k)
{
if(strcasecmp(team[k].name, team1) == 0)
break;
}
for(l=0; l < teams; ++l)
{
if(strcasecmp(team[l].name, team2) == 0)
break;
}
team[l].games++;
team[k].games++;
team[l].goals[1] += score1;
team[l].goals[0] += score2;
team[k].goals[0] += score1;
team[k].goals[1] += score2;
if(score1 < score2)
{
team[l].points += 3; /* Lose 1 and Win 2! */
team[k].result[2]++;
team[l].result[0]++;
}
else if(score1 > score2)
{
team[k].points += 3; /* Win 1 and Lose 2! */
team[l].result[2]++;
team[k].result[0]++;
}
else
{
team[k].points++; /* Tie between 1 */
team[l].points++; /* and 2! */
team[k].result[1]++;
team[l].result[1]++;
}
}
}
/* Calculates for to print OUTPUT */
printf("%s", tournament);
for(m=0; m < (teams - 1); ++m)
{
for(l=1; l < teams-m; ++l)
{
k=l-1;
/* Most points */
if(team[k].points < team[l].points)
{
team[lim_2] = team[k];
team[k] = team[l];
team[l] = team[lim_2];
}
/* Most wins */
else if(team[k].points == team[l].points && team[k].result[0] < team[l].result[0])
{
team[lim_2] = team[k];
team[k] = team[l];
team[l] = team[lim_2];
}
/* Most goals difference */
else if(team[k].points == team[l].points && team[k].result[0] == team[l].result[0] && (team[k].goals[0] - team[k].goals[1]) < (team[l].goals[0] - team[l].goals[1]))
{
team[lim_2] = team[k];
team[k] = team[l];
team[l] = team[lim_2];
}
/* Most goals scored */
else if(team[k].points == team[l].points && team[k].result[0] == team[l].result[0] && (team[k].goals[0] - team[k].goals[1]) == (team[l].goals[0] - team[l].goals[1]) && team[k].goals[0] < team[k].goals[0])
{
team[lim_2] = team[k];
team[k] = team[l];
team[l] = team[lim_2];
}
/* Less games played */
else if(team[k].points == team[l].points && team[k].result[0] == team[l].result[0] && (team[k].goals[0] - team[k].goals[1]) == (team[l].goals[0] - team[l].goals[1]) && team[k].goals[0] == team[l].goals[0] && team[k].games > team[l].games)
{
team[lim_2] = team[k];
team[k] = team[l];
team[l] = team[lim_2];
}
/* Case two teams are tied, the list is appears in lexicographic order. (OBS: Use of the function strcasecmp) */
else if(team[k].points == team[l].points && team[k].result[0] == team[l].result[0] && (team[k].goals[0] - team[k].goals[1]) == (team[l].goals[0] - team[l].goals[1]) && team[k].goals[0] == team[l].goals[0] && team[k].games == team[l].games && strcasecmp(team[k].name, team[l].name) >= 0 )//&& strlen(team[k].name)<strlen(team[l].name))
{
team[lim_2] = team[k];
team[k] = team[l];
team[l] = team[lim_2];
}
}
}
aux++;
/* Printing OUTPUT */
strcpy(previous,"");
for(j=0; j < teams; ++j)
{
if(strcmp(previous,team[j].name)!=0)
{
printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", aux, team[j].name, team[j].points, team[j].games, team[j].result[0], team[j].result[1], team[j].result[2], (team[j].goals[0] - team[j].goals[1]), team[j].goals[0], team[j].goals[1]);
aux++;
}
strcpy(previous,team[j].name);
}
if(i < (n_tournaments - 1))
printf("\n");
}
return 0;
}
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
struct team
{
char name[31];
int games;
int goalsA;
int goalsDif;
int goalsS;
int points;
int losses;
int ties;
int wins;
};
int timesCmp (const void *i, const void *j);
int main (void)
{
int g,n,t,i,j,k,maior,tempI[2];
char tournament[101],temp[3][31];
struct team *teams;
scanf("%d",&n);
getchar();
for ( i = 0 ; i < n ; i++ )
{
tempI[0] = tempI[1] = 0;
scanf("%100[^\n]",tournament);
scanf(" %d",&t);
getchar();
teams = (struct team *) malloc ( t * sizeof(struct team));
if (!teams) return 1;
for ( j = 0 ; j < t ; j++ )
{
teams[j].goalsDif = teams[j].points = teams[j].games = teams[j].goalsA = teams[j].goalsS = teams[j].losses = teams[j].ties = teams[j].wins = 0;
scanf("%30[^\n]",teams[j].name);
getchar();
}
scanf("%d",&g);
getchar();
for ( j = 0 ; j < g && j < 1000; j++)
{
/* Get the first team name */
scanf("%30[^#]",temp[0]);
getchar();
/* Get the first team Goals */
scanf("%2[^@]",temp[2]);
getchar();
tempI[0] = atoi(temp[2]);
/* Get the second team Goals */
scanf("%2[^#]",temp[2]);
getchar();
tempI[1] = atoi(temp[2]);
/* Get the second team name */
scanf("%30[^\n]",temp[1]);
getchar();
if ( tempI[0] > tempI[1] )
{
maior = 0;
}
else if ( tempI[0] < tempI[1] )
{
maior = 1;
}
else
{
maior = -1;
}
for ( k = 0 ; k < t ; k++ )
{
if ( strcmp(temp[0],teams[k].name) == 0 )
{
teams[k].goalsS += tempI[0];
teams[k].goalsA += tempI[1];
teams[k].goalsDif += tempI[0];
teams[k].goalsDif -= tempI[1];
if ( !maior )
{
teams[k].wins++;
teams[k].points += 3;
}
else if ( maior == 1 )
{
teams[k].losses++;
}
else
{
teams[k].ties++;
teams[k].points++;
}
teams[k].games++;
break;
}
}
for ( k = 0 ; k < t ; k++ )
{
if ( strcmp(temp[1],teams[k].name) == 0 )
{
teams[k].goalsS += tempI[1];
teams[k].goalsA += tempI[0];
teams[k].goalsDif += tempI[1];
teams[k].goalsDif -= tempI[0];
if ( maior == 1)
{
teams[k].wins++;
teams[k].points += 3;
}
else if ( !maior )
{
teams[k].losses++;
}
else
{
teams[k].ties++;
teams[k].points++;
}
teams[k].games++;
break;
}
}
}
qsort(teams , t , sizeof(struct team) , timesCmp);
printf("%s\n",tournament);
for ( j = 0 ; j < t ; j++ )
{
printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)",j+1,teams[j].name,teams[j].points,teams[j].games,teams[j].wins,teams[j].ties,teams[j].losses,teams[j].goalsDif,teams[j].goalsS,teams[j].goalsA);
if ( j != t-1 )
{
printf("\n");
}
}
if ( i != n-1 )
{
printf("\n\n");
}
else
{
printf("\n");
}
}
return 0;
}
int timesCmp (const void *i, const void *j)
{
struct team *a,*b;
a = (struct team *)i;
b = (struct team *)j;
if ( a->points > b->points )
{
return -1;
}
else if ( a->points == b->points )
{
if ( a->wins > b->wins )
{
return -1;
}
else if ( a->wins == b->wins )
{
if ( a->goalsDif > b->goalsDif )
{
return -1;
}
else if ( a->goalsDif == b->goalsDif )
{
if ( a->goalsS > b->goalsS )
{
return -1;
}
else if ( a->goalsS == b->goalsS )
{
if ( a->games > b->games )
{
return 1;
}
else if ( a->games == b->games )
{
return strcasecmp(a->name,b->name);
}
else
{
return -1;
}
}
else
{
return 1;
}
}
else
{
return 1;
}
}
else
{
return 1;
}
}
else
{
return 1;
}
}
Code: Select all
/* @JUDGE_ID: ******* 10194 C */
#include<stdio.h>
#include<string.h>
#include<stdlib.h> /* qsort */
#include<ctype.h> /* tolower */
#define NAME_LENGTH 33
struct info {
char name[NAME_LENGTH], temp_name[NAME_LENGTH];
int points;
int games;
int wins;
int ties;
int losses;
int difference;
int scored;
int against;
};
struct info team[30];
int cmp(const void *e1, const void *e2) {
struct info a, b;
a = *((const struct info *)e1);
b = *((const struct info *)e2);
if (a.points < b.points) return 1;
else if (a.points > b.points) return -1;
else if (a.wins < b.wins) return 1;
else if (a.wins > b.wins) return -1;
else if (a.difference < b.difference) return 1;
else if (a.difference > b.difference) return -1;
else if (a.scored < b.scored) return 1;
else if (a.scored > b.scored) return -1;
else if (a.games > b.games) return 1;
else if (a.games < b.games) return -1;
else if (strcmp(a.temp_name, b.temp_name)>0) return 1;
else if (strcmp(a.temp_name, b.temp_name)<0) return -1;
else return 0;
}
main() {
int N, T, G;
int set, i, j, len;
int score1, score2, n1, n2;
char tournament[101], team1[NAME_LENGTH], team2[NAME_LENGTH];
scanf("%d\n", &N);
for(set=N; set>0; set--) {
if(set!=N) printf("\n");
gets(tournament);
scanf("%d\n", &T);
for(i=0; i<T; i++) {
gets(team[i].name);
len = strlen(team[i].name);
for(j=0; j<len; j++) team[i].temp_name[j] = tolower(team[i].name[j]);
team[i].temp_name[len] = '\0';
team[i].points = team[i].games = team[i].wins = team[i].ties = 0;
team[i].losses = team[i].scored = team[i].against = 0;
}
scanf("%d\n", &G);
for(i=0; i<G; i++) {
scanf("%[^#]#%d@%d#%[^\n]\n", team1, &score1, &score2, team2);
/* search the team name from database */
for(j=0; j<T; j++) {
if(strcmp(team1, team[j].name)==0) {
n1 = j;
break;
}
}
for(j=0; j<T; j++) {
if(strcmp(team2, team[j].name)==0) {
n2 = j;
break;
}
}
/* put the info of the game into the database */
team[n1].games++;
team[n2].games++;
team[n1].scored += score1;
team[n2].scored += score2;
team[n1].against += score2;
team[n2].against += score1;
if(score1>score2) {
team[n1].wins++;
team[n2].losses++;
team[n1].points += 3;
}
else if(score1<score2) {
team[n2].wins++;
team[n1].losses++;
team[n2].points += 3;
}
else {
team[n1].ties++;
team[n2].ties++;
team[n1].points++;
team[n2].points++;
}
}
for(i=0; i<G; i++) {
team[i].difference = team[i].scored - team[i].against;
}
qsort(team, T, sizeof(struct info), cmp);
/* outputs the result of sorting */
printf("%s\n", tournament);
for(i=0; i<T; i++) {
printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", i+1, team[i].name, team[i].points, team[i].games, team[i].wins, team[i].ties, team[i].losses, team[i].difference, team[i].scored, team[i].against);
}
}
return 0;
}
Code: Select all
int comp(const void *a, const void *b)
{
st *x=(st *)a;
st *y=(st *)b;
if(x->pointEarned > y->pointEarned) return 1;
if(x->pointEarned <= y->pointEarned) return -1;
if(x->wins > y->wins) return 1;
if(x->wins < y->wins) return -1;
if(x->goalDiff > y->goalDiff) return 1;
if(x->goalDiff < y->goalDiff) return -1;
if(x->goalScored > y->goalScored) return 1;
if(x->goalScored < y->goalScored) return -1;
if(x->gamePlayed > y->gamePlayed) return -1;
if(x->gamePlayed < y->gamePlayed) return 1;
return strcmp(y->name,x->name);
}
Code: Select all
int comp(const void *a, const void *b)
{
st *x=(st *)a;
st *y=(st *)b;
if(x->pointEarned != y->pointEarned)
return(y->pointEarned - x->pointEarned); // the highest point come frist
if(x->wins != y->wins)
return(y->wins - x->wins); //highest win come frist
if(x->goalDiff != y->goalDiff)
return (y->goalDiff - x->goalDiff); //highest goaldiff come frist
if(x->goalScored != y->goalScored)
return(y->goalScored - x->goalScored); //highest goalscored come frist
if(x->gamePlayed != y->gamePlayed)
return(x->gamePlayed - y->gamePlayed); //less gameplayed come frist
return strcmp(x->name,y->name);
}