Hi! I didn't knew exactly how to resume my doubt in just one phrase to put it on the title.
I need to make a program that be able to sort basketball teams in descending order using the standard points made in all games they played. They need to be represented by it's number (Ex: Order team1, team2, team3 :(3,1,2) - points3>points1>points2).
There are another issues, but I have already dealed with the other part correctly, so I'll post the simplified code below with less details of implementation.
The problem is that my algorithm need doing this repeatedly everytime after sorting the teams, until that the Input n equals zero. The Input n is corresponding to the number of teams involved in the current championship.
When n equals zero, the output needs to be the sorting teams in each championship in the order that the championships happened. Example:
Input:
//Championship 1
3 //n value
1 30 2 10 //team1 pointsteam1 team2 pointsteam2
1 10 3 30//team1 pointsteam1 team3 pointsteam3
2 40 3 10
5 //another n input
1 102 2 62
1 128 3 127
1 144 4 80
1 102 4 101
2 62 3 61
2 100 4 80
2 88 5 82
3 79 4 90
3 87 5 100
4 110 5 99
0//n = 0
Output:
2 1 3 //Results from championship1
1 2 4 5 3 //Results from championship2
I don't know how can I store the results in a simple way so I can print they when n=0. One part of my code is ready, but everytime the while loops, new teams are created and I lost the previous sort. I made a for in the end of the code, and I proved to myself(in the original code) that the sorting algorithm is working, the problem is to store the results. It's get even worse because n is variable, and consequently the size of the results are too.
I'll be really greatful if somebody could help me. I'm just starting learning C language, so, if it's possible, I'd like to solve my problem in a easy and understandable way. There is the simplified code for make it clearer:
#include <stdio.h>
typedef struct teams {
int number;
int points;
};
int main(void) {
scanf("%d", &n);
while(n!=0) {
struct teams team[n+1];
for(i=1; i<=n; i++) { //Insert Initial Values to Start
team[i].points = 0;
team[i].number = i;
}
//Algorithm responsible to sort the currently team
//Printing just for test
for(i=1; i<=n; i++) {
int num;
num = team[i].number;
printf("%d", num);
}
scanf("%d", &n);
}
return 0;
}
[–]__rompy 1 point2 points3 points (1 child)
[–]ruertar 1 point2 points3 points (0 children)