Изменить 'du6/program.c'
This commit is contained in:
parent
145a134ede
commit
7c88c0f4aa
@ -1,14 +1,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int main(){
|
int main() {
|
||||||
int freePlaces;
|
int freePlaces;
|
||||||
char inputs[100][50];
|
char inputs[100][50];
|
||||||
for(int i = 0; i < 100; i++){
|
for(int i = 0; i < 100; i++)
|
||||||
memset(inputs[i], '\0', 50);
|
memset(inputs[i], '\0', 50);
|
||||||
}
|
|
||||||
char* ptr;
|
char* ptr;
|
||||||
int finalPosition;
|
int finalPosition;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -16,65 +15,58 @@ int main(){
|
|||||||
|
|
||||||
for(int i = 0; fgets(inputs[i], 50, stdin) != NULL; i++){
|
for(int i = 0; fgets(inputs[i], 50, stdin) != NULL; i++){
|
||||||
if(i == 0){
|
if(i == 0){
|
||||||
freePlaces = (int) strtol(inputs[0], &ptr, 10);
|
freePlaces = (int)strtol(inputs[i], &ptr, 10);
|
||||||
if(freePlaces < 0){
|
if(freePlaces < 0)
|
||||||
printf("Nespravny vstup %d\n", freePlaces);
|
printf("Nespravny vstup %d\n", freePlaces);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if(i == 1 && !isalpha(inputs[i][0])){
|
else if(i == 1 && !isalpha(inputs[i][0])){
|
||||||
printf("Ziadne prihlasky\n");
|
printf("Ziadne prihlasky\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(!strcmp(inputs[i], "") || inputs[i][0] == '\n'){
|
if(!strcmp(inputs[i], "") || inputs[i][0] == '\n')
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
finalPosition = i;
|
||||||
finalPosition = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Код ниже избавляется от повторных заявок
|
//The code below removes repeating applicants
|
||||||
|
|
||||||
for(int i = 0; i < finalPosition; i++){
|
for(int i = 0; i < finalPosition; i++){
|
||||||
for(int j = 0; j < finalPosition; j++){
|
for(int j = i+1; j < finalPosition; j++){
|
||||||
if(!strcmp(inputs[i], inputs[j])){
|
if(!strcmp(inputs[i], inputs[j])) {
|
||||||
strcpy(inputs[i], inputs[finalPosition]);
|
strcpy(inputs[i], inputs[finalPosition]);
|
||||||
memset(inputs[finalPosition], '\0', 50);
|
memset(inputs[finalPosition--], '\0', 50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Этот код отвечает за сортировку заданных имён в списке зачисленных (а-я)
|
//The code below orders the applicants by name (a-z)
|
||||||
int changesMade = 1;
|
int changesMade = 1;
|
||||||
while (changesMade){
|
while(changesMade){
|
||||||
changesMade = 0;
|
changesMade = 0;
|
||||||
for(int i = 0; i < finalPosition; i++){
|
for(int i = 0; i < finalPosition; i++){
|
||||||
while(inputs[i][count] == inputs[i+1][count]){
|
while(inputs[i][count] == inputs[i + 1][count])
|
||||||
count++;
|
count++;
|
||||||
}
|
if(inputs[i][count] > inputs[i + 1][count]){
|
||||||
if(inputs[i][count] > inputs[i+1][count]){
|
|
||||||
changesMade = 1;
|
changesMade = 1;
|
||||||
strcpy(temp, inputs[i]);
|
strcpy(temp, inputs[i]);
|
||||||
strcpy(inputs[i], inputs[i+1]);
|
strcpy(inputs[i], inputs[i + 1]);
|
||||||
strcpy(inputs[i+1], temp);
|
strcpy(inputs[i + 1], temp);
|
||||||
}
|
}
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Prijati studenti:\n");
|
printf("Prijati studenti:\n");
|
||||||
for(int i = 1; i <= freePlaces; i++) {
|
for(int i = 1; i <= freePlaces; i++){
|
||||||
if(isalpha(inputs[i][0])){
|
if(isalpha(inputs[i][0]))
|
||||||
printf ("%s", inputs[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(freePlaces < finalPosition) printf("Neprijati studenti:\n");
|
|
||||||
for(int i = freePlaces; i <= finalPosition; i++){
|
|
||||||
if(isalpha(inputs[i][0])){
|
|
||||||
printf("%s", inputs[i]);
|
printf("%s", inputs[i]);
|
||||||
}
|
}
|
||||||
|
if(freePlaces < finalPosition) printf("Neprijati studenti:\n");
|
||||||
|
for(int i = freePlaces; i < finalPosition; i++){
|
||||||
|
if(isalpha(inputs[i][0]))
|
||||||
|
printf("%s", inputs[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//free(ptr);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user