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