Aktualizovat „du5/program.c“

This commit is contained in:
Artem Horbunov 2020-04-07 15:15:09 +00:00
parent 45fc4c1d3d
commit 2377dc324c

View File

@ -5,6 +5,7 @@ int main(){
char name[50][50]; char name[50][50];
int score[50]; int score[50];
int pos = 0; int pos = 0;
//Getting input
while(1){ while(1){
scanf("%d %[^\n]", &score[pos], name[pos]); scanf("%d %[^\n]", &score[pos], name[pos]);
scanf("%*c"); scanf("%*c");
@ -18,6 +19,7 @@ int main(){
int newScore[50]; int newScore[50];
int newPos = 0; int newPos = 0;
//Combining names
for(int i = 0; i < pos; i++){ for(int i = 0; i < pos; i++){
int check = 0; int check = 0;
for(int q = 0; q < newPos; q++){ for(int q = 0; q < newPos; q++){
@ -35,15 +37,22 @@ int main(){
} }
} }
//Combining scores
for(int i = 0; i < newPos; i++){ for(int i = 0; i < newPos; i++){
for(int q = 0; q < pos; q++){ for(int q = 0; q < pos; q++){
if(strcmp(newName[i], name[q]) == 0) newScore[i] += score[q]; if(strcmp(newName[i], name[q]) == 0) newScore[i] += score[q];
} }
} }
// printf("Unsorted:\n");
// for(int i = 0; i < newPos; i++){
// printf("%d %s\n", newScore[i], newName[i]);
// }
//Sorting
for(int d = 0; d < newPos - 1; d++){ for(int d = 0; d < newPos - 1; d++){
for(int i = 0; i < newPos - 1; i++){ for(int i = 0; i < newPos - 1; i++){
if(newScore[i] < newScore[i + 1]){ if(newScore[i] < newScore[i + 1]){ //Score sorting
int tmpScore = newScore[i]; int tmpScore = newScore[i];
newScore[i] = newScore[i + 1]; newScore[i] = newScore[i + 1];
newScore[i + 1] = tmpScore; newScore[i + 1] = tmpScore;
@ -54,10 +63,11 @@ int main(){
strcpy(newName[i + 1], tmpName); strcpy(newName[i + 1], tmpName);
} }
else if(newScore[i] == newScore[i + 1]){ else if(newScore[i] == newScore[i + 1]){ //Name sorting
int test = 0; int test = 0;
for(int q = 0; q < newPos; q++){ for(int q = 0; q < newPos; q++){
if(newName[i][pos] < newName[i + 1][pos]){ if(newName[i][pos] < newName[i + 1][pos]){
printf("Letters %c %c\n", newName[i][pos], newName[i + 1][pos]);
int tmpScore = newScore[i]; int tmpScore = newScore[i];
newScore[i] = newScore[i + 1]; newScore[i] = newScore[i + 1];
newScore[i + 1] = tmpScore; newScore[i + 1] = tmpScore;
@ -66,17 +76,19 @@ int main(){
strcpy(tmpName, newName[i]); strcpy(tmpName, newName[i]);
strcpy(newName[i], newName[i + 1]); strcpy(newName[i], newName[i + 1]);
strcpy(newName[i + 1], tmpName); strcpy(newName[i + 1], tmpName);
printf("If\n");
break; break;
} }
else{ else if(newName[i][pos] > newName[i + 1][pos]){
int tmpScore = newScore[i + 1]; // int tmpScore = newScore[i + 1];
newScore[i + 1] = newScore[i]; // newScore[i + 1] = newScore[i];
newScore[i] = tmpScore; // newScore[i] = tmpScore;
char tmpName[50]; // char tmpName[50];
strcpy(tmpName, newName[i + 1]); // strcpy(tmpName, newName[i + 1]);
strcpy(newName[i + 1], newName[i]); // strcpy(newName[i + 1], newName[i]);
strcpy(newName[i], tmpName); // strcpy(newName[i], tmpName);
// printf("Else if\n");
break; break;
} }
} }