Advertisement
maxim_shlyahtin

ugabuga

Apr 17th, 2023
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #define BUFFER 100
  6. #define WORD_LEN 100
  7. #define TRUE 1
  8. #define FALSE 0
  9.  
  10. typedef struct Dictionary {
  11.     char **keys;
  12.     char **values;
  13.     int size;
  14. } dict;
  15.  
  16. dict *createDictionary(int size) {
  17.     dict *dictionary = (dict *) malloc(sizeof(dict *));
  18.     dictionary->size = size;
  19.     dictionary->keys = (char **) malloc(sizeof(char **) * dictionary->size);
  20.     dictionary->values = (char **) malloc(sizeof(char **) * dictionary->size);
  21.     for(int i = 0; i < BUFFER; i++){
  22.         dictionary->keys[i] = malloc(sizeof(char *) * WORD_LEN);
  23.         dictionary->values[i] = malloc(sizeof(char *) * WORD_LEN);
  24.     }
  25.     return dictionary;
  26. }
  27.  
  28. int main() {
  29.     dict *dict1 = createDictionary(BUFFER);
  30.     int n = 0;
  31.     char input[WORD_LEN];
  32.     while (TRUE) {
  33.         scanf("%s", input);
  34.         if (strcmp(input, "ugabuga") == 0)
  35.             break;
  36.         strcpy(dict1->keys[n], input);
  37.         scanf("%s", dict1->values[n]);
  38.         n++;
  39.     }
  40.     while (scanf("%s", input) != EOF) {
  41.         int found = FALSE;
  42.         for (int i = 0; i < n; i++) {
  43.             if (strcasecmp(input, dict1->keys[i]) == 0) {
  44.                 printf("%s", dict1->values[i]);
  45.                 found = TRUE;
  46.                 break;
  47.             }
  48.         }
  49.         if (!found)
  50.             printf("<unknown>");
  51.     }
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement