usaa20/cv1/program.c

94 lines
2.2 KiB
C
Raw Normal View History

2020-09-29 17:23:12 +00:00
#include <stdio.h>
#include <string.h>
2020-09-30 18:31:17 +00:00
#include <ctype.h>
#include <stdlib.h>
2020-09-29 17:23:12 +00:00
#define LINESIZE 100
#define LINE_SIZE 100
struct pizza {
float prize;
char name[LINESIZE];
};
2020-09-30 20:00:48 +00:00
2020-10-04 19:32:23 +00:00
int read_pizza(struct pizza* item);
2020-09-30 20:00:48 +00:00
int main(){
2020-09-29 17:23:12 +00:00
int POCET_JEDAL=0;
2020-10-03 11:03:18 +00:00
struct pizza jedalny_listok[POCET_JEDAL];
2020-09-29 17:23:12 +00:00
memset(jedalny_listok, 0,sizeof(struct pizza)*POCET_JEDAL);
char line[LINE_SIZE];
2020-10-04 19:32:23 +00:00
memset(line,0,LINE_SIZE);
char* r = fgets(line,LINE_SIZE,stdin);
if(r != NULL && line[1] != 0){
struct pizza item;
int counter = 1;
while(read_pizza(&item)){
counter += 1;
printf("%s",item.name);
printf("%.2f\n",item.prize);
}
}
}
int search_string(const char* heap, const char* needle){
int M=strlen(needle);
int N=strlen(heap);
for(int i=0;i<=N-M;i++){
int j;
for(j=0;j<M;j++){
if(heap[i+j]!=needle[j])
break;
}
if(j==M){
return i;
}
else{
return -1;
}
2020-09-30 20:24:59 +00:00
}
}
2020-10-04 19:32:23 +00:00
int read_pizza(struct pizza* item){
char line[LINE_SIZE];
memset(line,0,LINE_SIZE);
char* r = fgets(line,LINE_SIZE,stdin);
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);
2020-09-30 20:00:48 +00:00
if (value == 0.0F){
return 0;
}
item->prize = value;
strcpy(item->name, line);
return 1;
2020-09-30 18:31:17 +00:00
}
2020-10-04 19:32:23 +00:00
}
2020-09-30 18:31:17 +00:00
char hacker_script(char c){
char numbers[] = "0123456789";
char letters[] = "oizeasbtbq";
for (int i = 0; i < 10; i++){
2020-10-03 11:03:18 +00:00
if (c == numbers[i]){
2020-09-30 18:31:17 +00:00
return letters[i];
}
2020-09-29 17:23:12 +00:00
}
2020-10-04 19:32:23 +00:00
return tolower(c);
2020-09-29 17:23:12 +00:00
}
2020-09-30 20:24:59 +00:00
2020-09-30 18:31:17 +00:00
////////////////////////
2020-10-03 11:03:18 +00:00
// /////////
// /////// ///////
// //////// ///////
// //////// ///////
// ////// ////////
// //// //////////
// /////////////
2020-09-30 18:31:17 +00:00
// /// ///////////
// //// //////////
// ///// /////////
// ////// ////////
// /////// ///////
////////////////////////