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);
|
|
|
|
void Sort_Struct(struct LIS *,int);
|
|
|
|
void print(struct LIS *,int);
|
|
|
|
|
|
|
|
|
|
|
|
int main(){
|
|
|
|
struct LIS list[100];
|
|
|
|
int count=keep(list);
|
|
|
|
//printf("%d",count);
|
|
|
|
int pult=del(list,count);
|
|
|
|
//printf("%d",pult);
|
|
|
|
Sort_Struct(list,count);
|
|
|
|
print(list,count);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int keep(struct LIS *list){
|
|
|
|
char *array;
|
|
|
|
int stop,count;
|
|
|
|
int num;
|
|
|
|
for(int i=0; stop!=EOF; i++){
|
|
|
|
array=(char*)malloc(100);
|
|
|
|
stop =0;
|
|
|
|
for(int j=0;stop!='\n';j++){
|
|
|
|
stop=getchar();
|
|
|
|
if(stop==EOF) break;
|
2020-04-09 09:29:35 +00:00
|
|
|
if(stop!='\n'){
|
2020-04-08 18:19:24 +00:00
|
|
|
array[j]=stop;
|
2020-04-09 09:29:35 +00:00
|
|
|
}
|
2020-04-08 18:19:24 +00:00
|
|
|
}
|
|
|
|
if(stop==EOF) break;
|
|
|
|
sscanf(array,"%d %s %s",&list[i].num,list[i].sname,list[i].fname);
|
|
|
|
count++;
|
|
|
|
free(array);
|
|
|
|
}
|
|
|
|
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-08 21:28:42 +00:00
|
|
|
void Sort_Struct(struct LIS *list,int count){//bubble sort :)
|
2020-04-08 18:19:24 +00:00
|
|
|
struct LIS ilusion;
|
2020-04-09 09:37:19 +00:00
|
|
|
int val;
|
2020-04-08 18:19:24 +00:00
|
|
|
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-08 21:28:42 +00:00
|
|
|
if(list[i].num==list[j].num){
|
2020-04-09 09:45:27 +00:00
|
|
|
if(strlen(list[i].sname)>strlen(list[j].sname)){\
|
|
|
|
val=strlen(list[i].sname);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
val=strlen(list[j].sname);
|
|
|
|
}
|
|
|
|
for(int k=0;k<val;k++){
|
2020-04-09 09:29:35 +00:00
|
|
|
if(list[i].sname<list[j].sname && list[j].num!=-1 && list[i].num!=-1){
|
2020-04-08 21:28:42 +00:00
|
|
|
ilusion=list[i];
|
2020-04-09 09:37:19 +00:00
|
|
|
free(list[i].sname);
|
2020-04-08 21:28:42 +00:00
|
|
|
list[i]=list[j];
|
|
|
|
list[j]=ilusion;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-09 09:29:35 +00:00
|
|
|
if(list[i].num==list[j].num && list[i].sname==list[j].sname){
|
2020-04-09 09:45:27 +00:00
|
|
|
if(strlen(list[i].fname)>strlen(list[j].fname)){\
|
|
|
|
val=strlen(list[i].fname);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
val=strlen(list[j].fname);
|
|
|
|
}
|
|
|
|
for(int l=0;l<val;l++){
|
2020-04-09 09:29:35 +00:00
|
|
|
if(list[i].fname<list[j].fname && list[j].num!=-1 && list[i].num!=-1){
|
2020-04-08 21:32:41 +00:00
|
|
|
ilusion=list[i];
|
2020-04-09 09:37:19 +00:00
|
|
|
free(list[i].fname);
|
2020-04-08 21:32:41 +00:00
|
|
|
list[i]=list[j];
|
|
|
|
list[j]=ilusion;
|
|
|
|
}
|
|
|
|
}
|
2020-04-09 09:29:35 +00:00
|
|
|
}
|
2020-04-08 18:19:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void print(struct LIS *list,int count){
|
|
|
|
printf("Vysledky:\n");
|
|
|
|
for(int i=0;i<count;i++){
|
2020-04-08 18:24:37 +00:00
|
|
|
if(list[i].num!=-1 && list[i].num!=0){
|
2020-04-08 18:19:24 +00:00
|
|
|
printf("%d %s %s\n",list[i].num, list[i].sname, list[i].fname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-09 09:29:35 +00:00
|
|
|
|
|
|
|
|