funguje
This commit is contained in:
		
							parent
							
								
									c961194bc3
								
							
						
					
					
						commit
						c34908dce6
					
				| @ -32,11 +32,23 @@ int read_students(struct Student students[], int max_students) { | |||||||
|         char name[MAX_SIZE]; |         char name[MAX_SIZE]; | ||||||
|         // Ak sa nenačítajú dva prvky (počet hlasov a meno), skončíme
 |         // Ak sa nenačítajú dva prvky (počet hlasov a meno), skončíme
 | ||||||
|         if (sscanf(line, "%d %99[^\n]", &votes, name) == 2) { |         if (sscanf(line, "%d %99[^\n]", &votes, name) == 2) { | ||||||
|             strcpy(students[num_students].name, name); |             // Prejdeme všetkých študentov a ak nájdeme rovnaké meno, pripočítame hlasy
 | ||||||
|             students[num_students].votes = votes; |             int found = 0; | ||||||
|             num_students++; |             for (int i = 0; i < num_students; i++) { | ||||||
|             if (num_students >= max_students) { |                 if (strcmp(students[i].name, name) == 0) { | ||||||
|                 break; // Prekročený maximálny počet študentov
 |                     students[i].votes += votes; | ||||||
|  |                     found = 1; | ||||||
|  |                     break; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             // Ak sme nenašli rovnaké meno, pridáme nového študenta
 | ||||||
|  |             if (!found) { | ||||||
|  |                 strcpy(students[num_students].name, name); | ||||||
|  |                 students[num_students].votes = votes; | ||||||
|  |                 num_students++; | ||||||
|  |                 if (num_students >= max_students) { | ||||||
|  |                     break; // Prekročený maximálny počet študentov
 | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -47,7 +59,7 @@ int main() { | |||||||
|     struct Student students[MAX_STUDENTS]; |     struct Student students[MAX_STUDENTS]; | ||||||
|     int num_students = read_students(students, MAX_STUDENTS); |     int num_students = read_students(students, MAX_STUDENTS); | ||||||
| 
 | 
 | ||||||
|     // Zoradíme študentov podľa počtu hlasov
 |     // Zoradíme študentov podľa počtu hlasov a mena
 | ||||||
|     qsort(students, num_students, sizeof(struct Student), compare); |     qsort(students, num_students, sizeof(struct Student), compare); | ||||||
| 
 | 
 | ||||||
|     // Vypíšeme výsledky
 |     // Vypíšeme výsledky
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user