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 17:50:32 +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 18:56:39 +00:00
|
|
|
print(list,count);
|
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++){
|
2020-04-09 19:35:51 +00:00
|
|
|
// for(int i=0;list[count].fname[i]!='\0';i++);
|
2020-04-08 18:19:24 +00:00
|
|
|
}
|
|
|
|
return count;
|
2020-04-09 19:35:51 +00:00
|
|
|
|
2020-04-08 18:19:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int del(struct LIS *list,int count){
|
2020-04-09 18:44:33 +00:00
|
|
|
int kount=count;
|
2020-04-09 18:56:39 +00:00
|
|
|
for(int i=0;i<count;i++){
|
2020-04-09 18:47:23 +00:00
|
|
|
for(int j=i+1;j<count;j++){
|
2020-04-09 18:56:39 +00:00
|
|
|
if(strcmp(list[i].fname,list[j].fname)==0 && strcmp(list[i].sname,list[j].sname)==0 && list[j].num!=0) {
|
2020-04-09 18:44:33 +00:00
|
|
|
kount--;
|
2020-04-08 18:19:24 +00:00
|
|
|
list[i].num+=list[j].num;
|
2020-04-09 18:56:39 +00:00
|
|
|
list[j].num=0;
|
2020-04-09 18:47:23 +00:00
|
|
|
|
2020-04-08 18:19:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-09 18:47:23 +00:00
|
|
|
return kount;
|
2020-04-08 18:19:24 +00:00
|
|
|
}
|
|
|
|
|
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 18:56:39 +00:00
|
|
|
if(list[i].num<list[j].num && list[j].num!=0 && list[i].num!=0){
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-09 17:50:32 +00:00
|
|
|
void Sort_Sname(struct LIS *list,int count){//Selection Sort
|
2020-04-09 14:05:38 +00:00
|
|
|
struct LIS ilusion;
|
2020-04-09 17:50:32 +00:00
|
|
|
char *min;
|
|
|
|
int mini;
|
|
|
|
for(int i=0;i<count;i++){
|
|
|
|
min=list[i].sname;
|
|
|
|
mini=i;
|
|
|
|
for(int j=i+1;j<count;j++){
|
|
|
|
if((list[mini].num==list[j].num) && strcmp(min,list[j].sname)>0){
|
|
|
|
min=list[j].sname;
|
|
|
|
mini=j;
|
|
|
|
}
|
2020-04-09 14:05:38 +00:00
|
|
|
}
|
2020-04-09 17:50:32 +00:00
|
|
|
ilusion=list[i];
|
|
|
|
list[i]=list[mini];
|
|
|
|
list[mini]=ilusion;
|
2020-04-09 14:05:38 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-09 13:56:52 +00:00
|
|
|
|
2020-04-09 17:50:32 +00:00
|
|
|
|
2020-04-09 18:56:39 +00:00
|
|
|
void print(struct LIS *list,int count){
|
2020-04-09 19:35:51 +00:00
|
|
|
if(count!=0){
|
|
|
|
printf("Vysledky:\n");
|
|
|
|
for(int i=0;i<count;i++){
|
|
|
|
if(list[i].num!=0){
|
|
|
|
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 19:35:51 +00:00
|
|
|
else{
|
|
|
|
printf("Nepodarilo nacitat nic");
|
|
|
|
}
|
2020-04-08 18:19:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-09 09:29:35 +00:00
|
|
|
|
|
|
|
|
2020-04-09 12:48:18 +00:00
|
|
|
|
2020-04-09 17:50:32 +00:00
|
|
|
|