Обновить cv2/program.c

This commit is contained in:
Yevhen Kozirovskyi 2024-10-05 12:02:03 +00:00
parent 6d525d44f9
commit 34471f35b5

View File

@ -23,19 +23,34 @@ int main() {
if (strlen(dish) == 0) { if (strlen(dish) == 0) {
break; break;
} }
strcpy(dish_name[count], dish);
if (fgets(price, MAX_LENGTH, stdin) == NULL) { if (fgets(price, MAX_LENGTH, stdin) == NULL || strlen(price) == 0) {
break; break;
} }
price[strcspn(price, "\n")] = 0; price[strcspn(price, "\n")] = 0;
if (strlen(price) == 0) { char *endptr;
break; double current_price = strtod(price, &endptr);
if (*endptr != '\0' || strlen(price) == 0) {
continue;
} }
dish_price[count] = atof(price); int found = 0;
count++; for (int i = 0; i < count; i++) {
if (strcmp(dish_name[i], dish) == 0) {
found = 1;
if (current_price < dish_price[i]) {
dish_price[i] = current_price;
}
break;
}
}
if (!found) {
strcpy(dish_name[count], dish);
dish_price[count] = current_price;
count++;
}
} }
for (int i = 0; i < count - 1; i++) { for (int i = 0; i < count - 1; i++) {