test
This commit is contained in:
		
							parent
							
								
									374d5961e3
								
							
						
					
					
						commit
						924e6cea5b
					
				
							
								
								
									
										11
									
								
								cv2/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								cv2/Makefile
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
# variables
 | 
			
		||||
CC=gcc
 | 
			
		||||
CFLAGS=-std=c11 -Wall -Werror
 | 
			
		||||
LDLIBS=-lm
 | 
			
		||||
OUTPUT=$@
 | 
			
		||||
 | 
			
		||||
# targets
 | 
			
		||||
%: %.c
 | 
			
		||||
	$(CC) $(CFLAGS) $@.c $(LDLIBS) -o $(OUTPUT)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								cv2/program
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								cv2/program
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										67
									
								
								cv2/program.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								cv2/program.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,67 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <ctype.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <math.h>
 | 
			
		||||
 | 
			
		||||
#define velkost strlen
 | 
			
		||||
#define size 100
 | 
			
		||||
 | 
			
		||||
struct jedlo {
 | 
			
		||||
    char name[size];
 | 
			
		||||
    float price;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
int compare(const void* p1,const void*p2);
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
 | 
			
		||||
    struct jedlo databaza[size];
 | 
			
		||||
    char input[100]= {0};
 | 
			
		||||
    float price = 0;
 | 
			
		||||
    int counter = 0;
 | 
			
		||||
    int helper = 2;
 | 
			
		||||
    int counter2 = 0;
 | 
			
		||||
    int yes = 0;
 | 
			
		||||
    
 | 
			
		||||
    while(fgets(input, sizeof(input), stdin) && strcmp( input, "\n" ) != 0 ){
 | 
			
		||||
        if(helper %2 == 0){
 | 
			
		||||
            strcpy(databaza[counter].name, input);
 | 
			
		||||
            yes++;
 | 
			
		||||
        }
 | 
			
		||||
        else{
 | 
			
		||||
            price = strtof(input, NULL);
 | 
			
		||||
            databaza[counter].price = price;
 | 
			
		||||
            yes++;
 | 
			
		||||
        }
 | 
			
		||||
        if(yes == 2){
 | 
			
		||||
            counter++;
 | 
			
		||||
            yes = 0;
 | 
			
		||||
        }
 | 
			
		||||
        counter2++;
 | 
			
		||||
        helper++;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    counter2 = (counter2 / 2) - 1;
 | 
			
		||||
    qsort(databaza, counter2,sizeof(struct jedlo),compare);
 | 
			
		||||
 | 
			
		||||
    while(counter2 >= 0){
 | 
			
		||||
        printf("%s", databaza[counter2].name);
 | 
			
		||||
        printf("%f\n", databaza[counter2].price);
 | 
			
		||||
        counter2--;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int compare(const void* p1,const void*p2){
 | 
			
		||||
    struct jedlo* s1=(struct jedlo*)p1;
 | 
			
		||||
    struct jedlo* s2=(struct jedlo*)p2;
 | 
			
		||||
 | 
			
		||||
	if(s1->price == s2->price){
 | 
			
		||||
	    return 0;
 | 
			
		||||
	}
 | 
			
		||||
    else if(s1->price < s2->price){
 | 
			
		||||
	    return 1;
 | 
			
		||||
	}
 | 
			
		||||
	return -1;
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user