Update cv1/program.c
This commit is contained in:
		
							parent
							
								
									ba83fa2883
								
							
						
					
					
						commit
						a717c3fa01
					
				| @ -2,75 +2,77 @@ | |||||||
| #include <string.h> | #include <string.h> | ||||||
| #include <ctype.h> | #include <ctype.h> | ||||||
| 
 | 
 | ||||||
| // Funkcia na porovnanie znakov podľa pravidiel Hack3r scr1pt
 | // Функція для перевірки еквівалентності символів за правилами Hack3r scr1pt
 | ||||||
| int isHack3rEquivalent(char c1, char c2) { | int isHack3rEquivalent(char c1, char c2) { | ||||||
|     char table[256] = {0}; |     // Приведення до нижнього регістру для спрощення порівняння
 | ||||||
|     table['0'] = 'o'; table['o'] = '0'; |  | ||||||
|     table['1'] = 'i'; table['i'] = '1'; |  | ||||||
|     table['2'] = 'z'; table['z'] = '2'; |  | ||||||
|     table['3'] = 'e'; table['e'] = '3'; |  | ||||||
|     table['4'] = 'a'; table['a'] = '4'; |  | ||||||
|     table['5'] = 's'; table['s'] = '5'; |  | ||||||
|     table['6'] = 'b'; table['b'] = '6'; |  | ||||||
|     table['7'] = 't'; table['t'] = '7'; |  | ||||||
|     table['8'] = 'b'; table['b'] = '8'; |  | ||||||
|     table['9'] = 'q'; table['q'] = '9'; |  | ||||||
| 
 |  | ||||||
|     c1 = tolower(c1); |     c1 = tolower(c1); | ||||||
|     c2 = tolower(c2); |     c2 = tolower(c2); | ||||||
| 
 | 
 | ||||||
|     if (c1 == c2) return 1; |     // Таблиця замін символів згідно з правилами Hack3r scr1pt
 | ||||||
|     return table[(unsigned char)c1] == c2; |     if (c1 == c2) return 1;  // Якщо символи однакові
 | ||||||
|  |     if ((c1 == '0' && c2 == 'o') || (c1 == 'o' && c2 == '0')) return 1; | ||||||
|  |     if ((c1 == '1' && c2 == 'i') || (c1 == 'i' && c2 == '1')) return 1; | ||||||
|  |     if ((c1 == '2' && c2 == 'z') || (c1 == 'z' && c2 == '2')) return 1; | ||||||
|  |     if ((c1 == '3' && c2 == 'e') || (c1 == 'e' && c2 == '3')) return 1; | ||||||
|  |     if ((c1 == '4' && c2 == 'a') || (c1 == 'a' && c2 == '4')) return 1; | ||||||
|  |     if ((c1 == '5' && c2 == 's') || (c1 == 's' && c2 == '5')) return 1; | ||||||
|  |     if ((c1 == '7' && c2 == 't') || (c1 == 't' && c2 == '7')) return 1; | ||||||
|  |     if ((c1 == '8' && c2 == 'b') || (c1 == 'b' && c2 == '8')) return 1; | ||||||
|  |     return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Funkcia na zistenie, či sa reťazec hľadanej suroviny nachádza v názve jedla
 | // Функція для перевірки, чи містить назва страви шуканий інгредієнт
 | ||||||
| int isHack3rMatch(const char *name, const char *search) { | int isHack3rMatch(const char *name, const char *search) { | ||||||
|     int name_len = strlen(name); |     int name_len = strlen(name); | ||||||
|     int search_len = strlen(search); |     int search_len = strlen(search); | ||||||
| 
 | 
 | ||||||
|  |     // Перебір по назві страви
 | ||||||
|     for (int i = 0; i <= name_len - search_len; i++) { |     for (int i = 0; i <= name_len - search_len; i++) { | ||||||
|         int match = 1; |         int match = 1;  // Прапорець для перевірки відповідності
 | ||||||
|         for (int j = 0; j < search_len; j++) { |         for (int j = 0; j < search_len; j++) { | ||||||
|             if (!isHack3rEquivalent(name[i + j], search[j])) { |             if (!isHack3rEquivalent(name[i + j], search[j])) { | ||||||
|                 match = 0; |                 match = 0;  // Якщо хоч один символ не збігається, не підходить
 | ||||||
|                 break; |                 break; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         if (match) return 1; |         if (match) return 1;  // Якщо знайдено відповідність
 | ||||||
|     } |     } | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int main() { | int main() { | ||||||
|     char search[100]; |     char search[100];  // Шуканий інгредієнт
 | ||||||
|     char name[100]; |     char name[100];    // Назва страви
 | ||||||
|     char price[20]; |     char price[20];    // Ціна страви
 | ||||||
|     int count = 0; |     int count = 0;     // Лічильник оброблених страв
 | ||||||
| 
 | 
 | ||||||
|     printf("Zadaj hladanu surovinu:\n"); |     // Введення шуканого інгредієнта
 | ||||||
|  |     printf("Задай шуканий інгредієнт:\n"); | ||||||
|     fgets(search, sizeof(search), stdin); |     fgets(search, sizeof(search), stdin); | ||||||
|     search[strcspn(search, "\n")] = 0;  // odstráni znak nového riadku
 |     search[strcspn(search, "\n")] = 0;  // Видаляємо новий рядок
 | ||||||
| 
 | 
 | ||||||
|     printf("Zadaj jedalny listok:\n"); |     printf("Задай меню:\n"); | ||||||
| 
 | 
 | ||||||
|  |     // Обробка кожної страви з меню
 | ||||||
|     while (fgets(name, sizeof(name), stdin)) { |     while (fgets(name, sizeof(name), stdin)) { | ||||||
|         // Ak sa nepodarí načítať cenu alebo názov, prerušte načítanie
 |         // Якщо не вдалося прочитати ціну або назву, перериваємо обробку
 | ||||||
|         if (fgets(price, sizeof(price), stdin) == NULL || strlen(name) == 0) { |         if (fgets(price, sizeof(price), stdin) == NULL || strlen(name) == 0) { | ||||||
|             printf("Chyba pri nacitani.\n"); |             printf("Помилка при зчитуванні.\n"); | ||||||
|             break; |             break; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // odstráni znaky nového riadku
 |         // Видаляємо нові рядки з кінця назви та ціни
 | ||||||
|         name[strcspn(name, "\n")] = 0; |         name[strcspn(name, "\n")] = 0; | ||||||
|         price[strcspn(price, "\n")] = 0; |         price[strcspn(price, "\n")] = 0; | ||||||
| 
 | 
 | ||||||
|         // Skontroluje, či názov obsahuje hľadanú surovinu
 |         // Якщо назва містить шуканий інгредієнт
 | ||||||
|         if (isHack3rMatch(name, search)) { |         if (isHack3rMatch(name, search)) { | ||||||
|             printf("%s\n%s\n", name, price); |             printf("%s\n%s\n", name, price);  // Виводимо назву та ціну
 | ||||||
|         } |         } | ||||||
|         count++; |         count++;  // Збільшуємо лічильник оброблених страв
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     printf("Nacitanych %d poloziek.\n", count); |     // Виведення кількості оброблених позицій
 | ||||||
|     return 0; |     printf("Оброблено %d позицій.\n", count); | ||||||
|  |     return 0ж | ||||||
| } | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user