Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct Map {
- char* id;
- char* value;
- struct Map *next;
- } map;
- map* head = NULL;
- void add_elem(char* key, char* str){
- if (head == NULL){
- map* new = (map*) malloc (sizeof(map));
- head = new;
- new->id = (char*) malloc (strlen(key) +1);
- strcpy(new->id, key);
- new->value = (char*) malloc (strlen(str) + 1);
- strcpy(new->value, str);
- new->next = NULL;
- return;
- }
- map *tmp = head, *h = head;
- head = head->next;
- while (head){
- tmp = head;
- head = head->next;
- }
- map* new = (map*) malloc (sizeof(map));
- tmp->next = new;
- head = new;
- new->id = (char*) malloc (strlen(key) + 1);
- strcpy(new->id, key);
- new->value = (char*) malloc (strlen(str) + 1);
- strcpy(new->value, str);
- new->next = NULL;
- head = h;
- }
- void pop(char* id){
- map* h = head;
- if (head == NULL){
- printf("Error!\n");
- exit(1);
- }
- map* tmp = head;
- head = head->next;
- if (head == NULL){
- head = tmp;
- free(head);
- return;
- }
- if (strcmp(tmp->id, id) == 0){
- free(tmp);
- return;
- }
- while (head && strcmp(head->id, id)){
- tmp = head;
- head = head->next;
- }
- tmp->next = head->next;
- free(head);
- head = h;
- return;
- }
- char* get_value(char* id){
- map* h = head;
- map* tmp = head;
- if (strcasecmp(tmp->id, id) == 0){
- head = h;
- return tmp->value;
- }
- head = head->next;
- while (head){
- if (strcasecmp(head->id, id) == 0){
- head = h;
- return tmp->next->value;
- }
- tmp = head;
- head = head->next;
- }
- char* sss = "<unknown>";
- head = h;
- return sss;
- }
- void check_map(){
- map* h = head;
- while (head){
- printf("Key: %s, value: %s\n", head->id, head->value);
- head = head->next;
- }
- head = h;
- }
- void clean_buff(){
- while(getchar() != '\n'){;}
- }
- int main(){
- char str[200];
- char* ch = "ugabuga";
- char** arr = (char**) malloc (200* sizeof(char*));
- for (int i = 0; i < 200; i++)
- arr[i] = (char*) malloc (200*sizeof(char));
- int d = 0;
- scanf("%s", str);
- while(strcmp(str, ch)){
- strcpy(arr[d], str);
- d++;
- scanf("%s", str);
- }
- // for (int i = 0; i < d; i++)
- // printf("%s\n", arr[i]);
- for (int i = 0 ; i < d; i += 2){
- add_elem(arr[i], arr[i+1]);
- }
- clean_buff();
- char to_tr[200];
- fgets(to_tr, 200, stdin);
- to_tr[strlen(to_tr) - 1] = '\0';
- char* a[200];
- for (int i = 0; i < 200; i++)
- a[i] = (char*) malloc (200);
- int q = 0;
- char* pch = strtok(to_tr, " ");
- while(pch != NULL){
- strcpy(a[q], pch);
- q++;
- pch = strtok(NULL, " ");
- }
- for (int i = 0; i < q-1; i++)
- printf("%s ", get_value(a[i]));
- printf("%s\n", get_value(a[q-1]));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement