Update cv1/program.c
This commit is contained in:
		
							parent
							
								
									88a52f07f1
								
							
						
					
					
						commit
						f5d8c7855b
					
				| @ -11,7 +11,7 @@ struct pizza { | ||||
| }; | ||||
| 
 | ||||
| char hacker_script(char c) { | ||||
|     if (c >= 'A' && c <= 'Z') c += 32;  | ||||
|     if (c >= 'A' && c <= 'Z') c += 32; // Преобразование к нижнему регистру
 | ||||
|     switch (c) { | ||||
|         case 'o': return '0'; | ||||
|         case 'i': return '1'; | ||||
| @ -21,7 +21,7 @@ char hacker_script(char c) { | ||||
|         case 's': return '5'; | ||||
|         case 'b': return '6'; | ||||
|         case 't': return '7'; | ||||
|         case '8': return '8';  | ||||
|         case '8': return '8'; | ||||
|         case 'q': return '9'; | ||||
|         default: return c; | ||||
|     } | ||||
| @ -29,23 +29,25 @@ char hacker_script(char c) { | ||||
| 
 | ||||
| void normalize_string(const char* input, char* output) { | ||||
|     int i = 0; | ||||
|     while (input[i] != '\0' && input[i] != '\n') {   | ||||
|     while (input[i] != '\0' && input[i] != '\n') {  // Убираем '\n'
 | ||||
|         output[i] = hacker_script(input[i]); | ||||
|         i++; | ||||
|     } | ||||
|     output[i] = '\0';   | ||||
|     output[i] = '\0';  // Завершаем строку
 | ||||
| } | ||||
| 
 | ||||
| int read_pizza(struct pizza* item) { | ||||
|     char line[LINESIZE]; | ||||
|     if (fgets(line, sizeof(line), stdin) == NULL) return 0; | ||||
| 
 | ||||
|     normalize_string(line, item->name);  | ||||
|     if (fgets(line, sizeof(line), stdin) == NULL) return 0; | ||||
|     item->prize = strtof(line, NULL);  | ||||
|     normalize_string(line, item->name); // Преобразуем название
 | ||||
| 
 | ||||
|     return (item->prize > 0) ? 1 : 0;  | ||||
|     if (fgets(line, sizeof(line), stdin) == NULL) return 0; | ||||
|     item->prize = strtof(line, NULL); // Преобразуем цену
 | ||||
| 
 | ||||
|     return (item->prize > 0) ? 1 : 0; // Успех или ошибка
 | ||||
| } | ||||
| 
 | ||||
| int find_string(const char* heap, const char* needle) { | ||||
|     char normalized_heap[LINESIZE]; | ||||
|     char normalized_needle[LINESIZE]; | ||||
| @ -60,24 +62,35 @@ int main() { | ||||
|     int item_count = 0; | ||||
| 
 | ||||
|     char search_term[LINESIZE]; | ||||
|     printf("Zadaj hladanu surovinu:\n"); | ||||
|     printf("Zadaj hladanu surovinu:\n"); // Первое сообщение
 | ||||
|     fgets(search_term, sizeof(search_term), stdin); | ||||
|      | ||||
|      | ||||
|     // Удаляем '\n' из поискового запроса
 | ||||
|     search_term[strcspn(search_term, "\n")] = '\0';  | ||||
| 
 | ||||
|     printf("Zadaj jedalny listok:\n"); | ||||
|     printf("Zadaj jedalny listok:\n"); // Второе сообщение
 | ||||
|     while (item_count < MENU_SIZE && read_pizza(&menu[item_count])) { | ||||
|         item_count++; | ||||
|     } | ||||
| 
 | ||||
|     | ||||
|     // Флаг для проверки, был ли найден хотя бы один элемент
 | ||||
|     int found = 0; | ||||
| 
 | ||||
|     // Печать подходящих элементов
 | ||||
|     for (int i = 0; i < item_count; i++) { | ||||
|         if (find_string(menu[i].name, search_term)) { | ||||
|             printf("%s\n%.2f\n", menu[i].name, menu[i].prize); | ||||
|             found = 1; // Найдено совпадение
 | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     printf("Nacitanych %d poloziek.\n", item_count); | ||||
|     // Если совпадений нет, ничего не выводится, иначе выводим количество
 | ||||
|     if (found) { | ||||
|         printf("Nacitanych %d poloziek.\n", item_count); | ||||
|     } else { | ||||
|         // Выводим только количество, если совпадений нет
 | ||||
|         printf("Nacitanych %d poloziek.\n", item_count); | ||||
|     } | ||||
| 
 | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user