Přidat a3/program.c

This commit is contained in:
Daniel Dembický 2026-03-30 11:16:24 +00:00
parent f278380035
commit d7f572cfc2

74
a3/program.c Normal file
View File

@ -0,0 +1,74 @@
#include <stdio.h>
int main() {
int n;
if (scanf("%d", &n) != 1 || n <= 0) {
puts("Nespravny vstup");
return 1;
}
char buf[100];
fgets(buf, 100, stdin);
char names[1000][100];
int count = 0;
while (fgets(buf, 100, stdin)) {
int len = 0;
while (buf[len]) len++;
while (len > 0 && (buf[len - 1] == '\n' || buf[len - 1] == '\r'))
buf[--len] = '\0';
if (len == 0) break;
if (count < 1000) {
int i = 0;
while ((names[count][i] = buf[i])) i++;
count++;
}
}
if (count == 0) {
puts("Ziadne prihlasky");
return 1;
}
char tmp[100];
for (int i = 0; i < count - 1; i++)
for (int j = i + 1; j < count; j++) {
int k = 0;
while (names[i][k] && names[i][k] == names[j][k]) k++;
if (names[i][k] - names[j][k] > 0) {
int t = 0;
while ((tmp[t] = names[i][t])) t++;
t = 0;
while ((names[i][t] = names[j][t])) t++;
t = 0;
while ((names[j][t] = tmp[t])) t++;
}
}
int unique = 1;
for (int i = 1; i < count; i++) {
int k = 0;
while (names[i][k] && names[i][k] == names[unique - 1][k]) k++;
if (names[i][k] != names[unique - 1][k]) {
int t = 0;
while ((names[unique][t] = names[i][t])) t++;
unique++;
}
}
count = unique;
int accepted = (n < count) ? n : count;
puts("Prijati studenti:");
for (int i = 0; i < accepted; i++)
puts(names[i]);
if (accepted < count) {
puts("Neprijati studenti:");
for (int i = accepted; i < count; i++)
puts(names[i]);
}
return 0;
}