Обновить cv1/program.c
This commit is contained in:
		
							parent
							
								
									9ebc2542f3
								
							
						
					
					
						commit
						29a04f727c
					
				| @ -1,8 +1,10 @@ | ||||
| #include <stdio.h> | ||||
| #include <string.h> | ||||
| #include <ctype.h> | ||||
| 
 | ||||
| #define MAX_DISHES 100 | ||||
| #define MAX_NAME_LEN 100 | ||||
| 
 | ||||
| void decodovane_slovo(char *text) { | ||||
|     for (int i = 0; text[i]; i++) { | ||||
|         switch (text[i]) { | ||||
| @ -20,6 +22,7 @@ void decodovane_slovo(char *text) { | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| int main() { | ||||
|     char ingredient[MAX_NAME_LEN]; | ||||
|     char dishes[MAX_DISHES][2][MAX_NAME_LEN]; | ||||
| @ -29,7 +32,7 @@ int main() { | ||||
|     if (fgets(ingredient, MAX_NAME_LEN, stdin) == NULL) { | ||||
|         return 0; | ||||
|     } | ||||
| 
 | ||||
|     ingredient[strcspn(ingredient, "\n")] = '\0';  // Удаление символа новой строки
 | ||||
| 
 | ||||
|     printf("Zadaj jedalny listok:\n"); | ||||
|     while (1) { | ||||
| @ -38,15 +41,16 @@ int main() { | ||||
|         if (fgets(name, MAX_NAME_LEN, stdin) == NULL) { | ||||
|             return 0; | ||||
|         } | ||||
|         name[strcspn(name, "\n")] = '\0'; | ||||
|         name[strcspn(name, "\n")] = '\0';  // Удаление символа новой строки
 | ||||
| 
 | ||||
|         if (strlen(name) == 0) { | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         if (fgets(price, MAX_NAME_LEN, stdin) == NULL) { | ||||
|             return 0; | ||||
|         } | ||||
|         price[strcspn(price, "\n")] = '\0'; | ||||
|         price[strcspn(price, "\n")] = '\0';  // Удаление символа новой строки
 | ||||
| 
 | ||||
|         strncpy(dishes[count][0], name, MAX_NAME_LEN - 1); | ||||
|         dishes[count][0][MAX_NAME_LEN - 1] = '\0'; | ||||
| @ -56,22 +60,21 @@ int main() { | ||||
| 
 | ||||
|         count++; | ||||
|     } | ||||
|     decodovane_slovo(ingredient); | ||||
| 
 | ||||
|     decodovane_slovo(ingredient);  // Декодируем ингредиент
 | ||||
| 
 | ||||
|     for (int i = 0; i < count; i++) { | ||||
|         char decoded_name[MAX_NAME_LEN]; | ||||
|         strncpy(decoded_name, dishes[i][0], MAX_NAME_LEN - 1); | ||||
|         decoded_name[MAX_NAME_LEN - 1] = '\0'; | ||||
| 
 | ||||
|         decodovane_slovo(decoded_name); | ||||
|         decodovane_slovo(decoded_name);  // Декодируем имя блюда
 | ||||
| 
 | ||||
|         if (strstr(decoded_name, ingredient) != NULL) { | ||||
|             printf("%s%s", dishes[i][0], dishes[i][1]); | ||||
|             if (i < count - 1) { | ||||
|                 printf("\n"); | ||||
|             } | ||||
|             printf("%s %s\n", dishes[i][0], dishes[i][1]); | ||||
|         } | ||||
|     } | ||||
|     printf("Nacitanych %d poloziek.", count); | ||||
| 
 | ||||
|     printf("Nacitanych %d poloziek.\n", count); | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user