2020-10-09 10:19:52 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define LINESIZE 100
|
|
|
|
#define LINE_SIZE 100
|
2020-10-13 16:33:00 +00:00
|
|
|
#define POCET_JEDAL 100
|
2020-10-09 10:19:52 +00:00
|
|
|
struct pizza {
|
|
|
|
float prize;
|
|
|
|
char name[LINESIZE];
|
|
|
|
};
|
|
|
|
void trim(char* str);
|
|
|
|
int search_string(const char* heap, const char* needle);
|
|
|
|
int read_pizza(struct pizza* item);
|
|
|
|
char hacker_script(char c);
|
|
|
|
|
|
|
|
int main(){
|
|
|
|
struct pizza jedalny_listok[POCET_JEDAL];
|
|
|
|
memset(jedalny_listok, 0,sizeof(struct pizza)*POCET_JEDAL);
|
|
|
|
int counter=0;
|
2020-10-13 15:02:34 +00:00
|
|
|
//char line[LINE_SIZE];
|
|
|
|
//memset(line,0,LINE_SIZE);
|
2020-10-13 16:25:34 +00:00
|
|
|
|
2020-10-13 15:02:34 +00:00
|
|
|
struct pizza item;
|
|
|
|
while(read_pizza(&item)){
|
|
|
|
strcpy(jedalny_listok[counter].name, item.name);
|
|
|
|
jedalny_listok[counter].prize=item.prize;
|
|
|
|
counter += 1;
|
|
|
|
if (counter>=POCET_JEDAL)
|
|
|
|
{
|
|
|
|
break;
|
2020-10-09 10:19:52 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-13 16:25:34 +00:00
|
|
|
for(int i=0;i<counter-1;i++){
|
|
|
|
for(int j=0;j<counter-i;j++){
|
|
|
|
if(j<counter-1-i){
|
|
|
|
if(jedalny_listok[j].prize>jedalny_listok[j+1].prize){
|
|
|
|
struct pizza temp=jedalny_listok[j];
|
|
|
|
jedalny_listok[j]=jedalny_listok[j+1];
|
|
|
|
jedalny_listok[j+1]=temp;
|
|
|
|
}
|
|
|
|
else if (jedalny_listok[j].prize==jedalny_listok[j+1].prize){
|
|
|
|
if(strcmp(jedalny_listok[j].name,jedalny_listok[j+1].name)>0){
|
|
|
|
struct pizza temp=jedalny_listok[j];
|
|
|
|
jedalny_listok[j]=jedalny_listok[j+1];
|
|
|
|
jedalny_listok[j+1]=temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-09 10:19:52 +00:00
|
|
|
for(int i=0;i<counter;i++){
|
2020-10-13 15:02:34 +00:00
|
|
|
printf("%s\n",jedalny_listok[i].name);
|
2020-10-13 16:30:22 +00:00
|
|
|
printf("%.6f\n",jedalny_listok[i].prize);
|
2020-10-09 10:19:52 +00:00
|
|
|
//printf("daco\n");
|
|
|
|
}
|
2020-10-13 15:02:34 +00:00
|
|
|
|
2020-10-13 16:25:34 +00:00
|
|
|
}
|
2020-10-09 10:19:52 +00:00
|
|
|
void trim(char* str){
|
|
|
|
int i=0;
|
|
|
|
while(str[i]!='\n'&&str[i]!=0){
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
str[i]=0;
|
|
|
|
}
|
2020-10-13 15:02:34 +00:00
|
|
|
/*
|
2020-10-09 10:19:52 +00:00
|
|
|
int search_string(const char* heap, const char* needle){
|
|
|
|
int M=strlen(needle);
|
|
|
|
int N=strlen(heap);
|
|
|
|
//printf("needle:%d heap: %d\n",M,N);
|
|
|
|
for(int i=0;i<=N-M;i++){
|
|
|
|
int j;
|
|
|
|
for(j=0;j<M;j++){
|
|
|
|
//printf("heap:%c\n",hacker_script(heap[i+j]));
|
|
|
|
//printf("needle:%c\n",hacker_script(needle[j]));
|
|
|
|
if(hacker_script(heap[i+j])!=hacker_script(needle[j])){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(j==M){
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
2020-10-13 15:02:34 +00:00
|
|
|
}*/
|
2020-10-09 10:19:52 +00:00
|
|
|
int read_pizza(struct pizza* item){
|
|
|
|
char line[LINE_SIZE];
|
|
|
|
memset(line,0,LINE_SIZE);
|
|
|
|
char* r = fgets(line,LINE_SIZE,stdin);
|
|
|
|
trim(line);
|
|
|
|
//printf("%s\n",line);
|
|
|
|
if(r != NULL && line[1] != 0){
|
|
|
|
char line2[LINE_SIZE];
|
|
|
|
memset(line2,0,LINE_SIZE);
|
|
|
|
fgets(line2,LINE_SIZE,stdin);
|
|
|
|
float value = strtof(line2,NULL);
|
|
|
|
if (value == 0.0F){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
item->prize = value;
|
|
|
|
strcpy(item->name, line);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2020-10-13 15:02:34 +00:00
|
|
|
/*char hacker_script(char c){
|
2020-10-09 10:19:52 +00:00
|
|
|
char numbers[] = "0123456789";
|
|
|
|
char letters[] = "oizeasbtbq";
|
|
|
|
for (int i = 0; i < 10; i++){
|
|
|
|
if (c == numbers[i]){
|
|
|
|
return letters[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tolower(c);
|
2020-10-13 15:02:34 +00:00
|
|
|
}*/
|
2020-10-09 10:19:52 +00:00
|
|
|
|
|
|
|
////////////////////////
|
2020-10-13 15:02:34 +00:00
|
|
|
/// /////////
|
|
|
|
// ////// ///////
|
|
|
|
// /////// ///////
|
2020-10-09 10:19:52 +00:00
|
|
|
// /////// ///////
|
|
|
|
// ////// ////////
|
|
|
|
// //// //////////
|
2020-10-13 15:02:34 +00:00
|
|
|
// ////////////
|
2020-10-09 10:19:52 +00:00
|
|
|
// /// ///////////
|
|
|
|
// //// //////////
|
|
|
|
// ///// /////////
|
|
|
|
// ////// ////////
|
2020-10-13 15:02:34 +00:00
|
|
|
// //////// ///////
|
2020-10-09 10:19:52 +00:00
|
|
|
////////////////////////
|