pvjc20/du5/program.c

106 lines
2.4 KiB
C
Raw Normal View History

2020-04-08 18:19:24 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
struct LIS{
char fname[100];
char sname[100];
int num;
};
int keep(struct LIS *);
int del(struct LIS *,int);
2020-04-09 12:48:18 +00:00
void Sort_Num(struct LIS *,int);
void Sort_Sname(struct LIS *,int);
2020-04-09 14:05:38 +00:00
void Sort_Fname(struct LIS *,int);
2020-04-08 18:19:24 +00:00
void print(struct LIS *,int);
int main(){
struct LIS list[100];
int count=keep(list);
2020-04-09 10:05:23 +00:00
int pult=del(list,count);
2020-04-09 12:48:18 +00:00
Sort_Num(list,count);
Sort_Sname(list,count);
2020-04-09 14:05:38 +00:00
Sort_Fname(list,count);
2020-04-09 12:48:18 +00:00
print(list,pult);
2020-04-08 18:19:24 +00:00
return 0;
}
int keep(struct LIS *list){
2020-04-09 10:05:23 +00:00
int count;
for(count=0;fscanf(stdin,"%d %s %s",&list[count].num, list[count].sname, list[count].fname)==3;count++){
for(int i=0;list[count].fname[i]!='\0';i++);
2020-04-08 18:19:24 +00:00
}
return count;
}
int del(struct LIS *list,int count){
for(int i=0;i<count-1;i++){
for(int j=i+1;j<count;j++){
if(strcmp(list[i].fname,list[j].fname)==0 && strcmp(list[i].sname,list[j].sname)==0 && list[j].num!=-1) {
count--;
list[i].num+=list[j].num;
list[j].num=-1;
}
}
}
return count;
}
2020-04-09 12:48:18 +00:00
void Sort_Num(struct LIS *list,int count){//bubble sort :)
2020-04-08 18:19:24 +00:00
struct LIS ilusion;
for(int i=0;i<count;i++){
2020-04-08 21:13:23 +00:00
for(int j=count;j>i;j--){
2020-04-09 09:29:35 +00:00
if(list[i].num<list[j].num && list[j].num!=-1 && list[i].num!=-1){
2020-04-08 21:13:23 +00:00
ilusion=list[i];
list[i]=list[j];
list[j]=ilusion;
2020-04-08 18:19:24 +00:00
}
2020-04-09 12:48:18 +00:00
}
}
}
void Sort_Sname(struct LIS *list,int count){
struct LIS ilusion;
2020-04-09 13:56:52 +00:00
for(int i=count-1;i<0;i--){
for(int j=0;j<i;j++){
2020-04-09 14:08:38 +00:00
if(list[j].num==list[j+1].num && strcmp(list[j].sname,list[j+1].sname)<0 ){
2020-04-09 13:56:52 +00:00
ilusion=list[j];
list[j]=list[j+1];
list[j+1]=ilusion;
2020-04-09 12:48:18 +00:00
}
2020-04-08 18:19:24 +00:00
}
}
}
2020-04-09 14:05:38 +00:00
void Sort_Fname(struct LIS *list,int count){
struct LIS ilusion;
for(int i=count-1;i<0;i--){
for(int j=0;j<i;j++){
2020-04-09 14:07:53 +00:00
if(list[j].num==list[j+1].num && list[j].sname==list[j+1].sname && strcmp(list[j].fname,list[j+1].fname)>0) {
2020-04-09 14:05:38 +00:00
ilusion=list[j];
list[j]=list[j+1];
list[j+1]=ilusion;
}
}
}
}
2020-04-09 13:56:52 +00:00
2020-04-09 12:48:18 +00:00
void print(struct LIS *list,int pult){
2020-04-08 18:19:24 +00:00
printf("Vysledky:\n");
2020-04-09 12:48:18 +00:00
for(int i=0;i<pult;i++){
2020-04-08 18:24:37 +00:00
if(list[i].num!=-1 && list[i].num!=0){
2020-04-09 13:56:52 +00:00
printf("%d %s %s\n",list[i].num, list[i].sname, list[i].fname);
2020-04-08 18:19:24 +00:00
}
}
}
2020-04-09 09:29:35 +00:00
2020-04-09 12:48:18 +00:00