108 lines
2.5 KiB
C
108 lines
2.5 KiB
C
#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;
|
|
int ss;
|
|
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;
|
|
array[j]=stop;
|
|
}
|
|
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;
|
|
}
|
|
|
|
void Sort_Struct(struct LIS *list,int count){//bubble sort :)
|
|
struct LIS ilusion;
|
|
for(int i=0;i<count;i++){
|
|
for(int j=count;j>i;j--){
|
|
if(list[i].num<list[j].num){
|
|
ilusion=list[i];
|
|
list[i]=list[j];
|
|
list[j]=ilusion;
|
|
}
|
|
if(list[i].num==list[j].num){
|
|
for(int k=0;k<strlen(list[i].sname);k++){
|
|
if(list[i].sname<list[j].sname){
|
|
ilusion=list[i];
|
|
list[i]=list[j];
|
|
list[j]=ilusion;
|
|
}
|
|
}
|
|
}
|
|
if(list[i].num==list[j].num && list[i].sname==list[j].sname){
|
|
for(int l=0;l<strlen(list[i].fname);l++){
|
|
if(list[i].fname<list[j].fname){
|
|
ilusion=list[i];
|
|
list[i]=list[j];
|
|
list[j]=ilusion;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void print(struct LIS *list,int count){
|
|
printf("Vysledky:\n");
|
|
for(int i=0;i<count;i++){
|
|
if(list[i].num!=-1 && list[i].num!=0){
|
|
printf("%d %s %s\n",list[i].num, list[i].sname, list[i].fname);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|