Изменить 'du5/program.c'
This commit is contained in:
parent
c1c3dcd0d0
commit
408a2e654c
108
du5/program.c
108
du5/program.c
@ -1,107 +1 @@
|
||||
#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_Num(struct LIS *,int);
|
||||
void Sort_Sname(struct LIS *,int);
|
||||
//void Sort_Fname(struct LIS *,int);
|
||||
void print(struct LIS *,int);
|
||||
|
||||
|
||||
int main(){
|
||||
struct LIS list[100];
|
||||
int count=keep(list);
|
||||
int pult=del(list,count);
|
||||
Sort_Num(list,count);
|
||||
Sort_Sname(list,count);
|
||||
print(list,count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int keep(struct LIS *list){
|
||||
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++);
|
||||
}
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
int del(struct LIS *list,int count){
|
||||
int kount=count;
|
||||
for(int i=0;i<count;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!=0) {
|
||||
kount--;
|
||||
list[i].num+=list[j].num;
|
||||
list[j].num=0;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return kount;
|
||||
}
|
||||
|
||||
void Sort_Num(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 && list[j].num!=0 && list[i].num!=0){
|
||||
ilusion=list[i];
|
||||
list[i]=list[j];
|
||||
list[j]=ilusion;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void Sort_Sname(struct LIS *list,int count){//Selection Sort
|
||||
struct LIS ilusion;
|
||||
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;
|
||||
}
|
||||
}
|
||||
ilusion=list[i];
|
||||
list[i]=list[mini];
|
||||
list[mini]=ilusion;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void print(struct LIS *list,int count){
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
printf("Nepodarilo nacitat nic\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
фы
|
Loading…
Reference in New Issue
Block a user