added everything except sort and weighting, will finish after lunch
This commit is contained in:
parent
f41f1b9862
commit
7cd5414a22
29
rank.c
29
rank.c
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
#define M_STR 255
|
#define M_STR 255
|
||||||
|
|
||||||
|
void isort(char *, int *, int);
|
||||||
|
|
||||||
int
|
int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
@ -18,7 +20,7 @@ main(void)
|
|||||||
char strings[M_STR][255] = { 0 };
|
char strings[M_STR][255] = { 0 };
|
||||||
|
|
||||||
// read strings
|
// read strings
|
||||||
printf(BOLDWHITE "Enter strings: (empty line when done) \n" RESET);
|
printf(BOLDWHITE "Enter a ranking (empty line when done) \n" RESET);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < M_STR; i++) {
|
for (i = 0; i < M_STR; i++) {
|
||||||
@ -43,11 +45,12 @@ main(void)
|
|||||||
|
|
||||||
// store the winners
|
// store the winners
|
||||||
int winners[i];
|
int winners[i];
|
||||||
|
int sorted_winners[i];
|
||||||
|
|
||||||
printf("%d: %d\n", i, sizeof(winners));
|
|
||||||
|
|
||||||
// memcpy(3) with null bytes
|
// memcpy(3) with null bytes
|
||||||
memset(winners, 0, sizeof(winners));
|
memset(winners, 0, sizeof(winners));
|
||||||
|
memset(sorted_winners, 0, sizeof(sorted_winners));
|
||||||
|
|
||||||
// compare all of the elements
|
// compare all of the elements
|
||||||
for (int j = 0; j < i; j++) {
|
for (int j = 0; j < i; j++) {
|
||||||
@ -58,17 +61,32 @@ main(void)
|
|||||||
if (c == '>') {
|
if (c == '>') {
|
||||||
matrix[j][k] = 1;
|
matrix[j][k] = 1;
|
||||||
winners[j]++;
|
winners[j]++;
|
||||||
|
sorted_winners[j]++;
|
||||||
} else if (c == '<') {
|
} else if (c == '<') {
|
||||||
matrix[j][k] = 0;
|
matrix[j][k] = 0;
|
||||||
winners[k]++;
|
winners[k]++;
|
||||||
|
sorted_winners[k]++;
|
||||||
} else {
|
} else {
|
||||||
printf("Setting to " BOLDRED "<" RESET ": %c\n", c);
|
printf("Setting to " BOLDRED "<" RESET ": %c\n", c);
|
||||||
matrix[j][k] = 0;
|
matrix[j][k] = 0;
|
||||||
|
winners[k]++;
|
||||||
|
sorted_winners[k]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clear input buffer
|
||||||
|
while (getchar() != '\n');
|
||||||
|
|
||||||
|
// ask the user to explain their choice; but we don't care what
|
||||||
|
// they say
|
||||||
|
printf(BOLDWHITE "Explain: " RESET);
|
||||||
|
|
||||||
|
while (getchar() != '\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// insertion sort: the array **should be** nearly sorted
|
||||||
|
isort(strings, sorted_winners, i);
|
||||||
|
|
||||||
// print out the results
|
// print out the results
|
||||||
for (int j = 0; j < i; j++) {
|
for (int j = 0; j < i; j++) {
|
||||||
printf("%s: %d\n", strings[j], winners[j]);
|
printf("%s: %d\n", strings[j], winners[j]);
|
||||||
@ -76,3 +94,10 @@ main(void)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
isort(char *key, int *value, int i) {
|
||||||
|
// sort by value, modify key accordingly
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user