In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of April 7th
(this exercise will still be available for submission after that deadline, but without couting towards your grade)
[to understand the context of this problem, you should read the class #05 exercise sheet]


In this problem you should submit a file containing the function as described (without any main function). Inside the function do not print anything that was not asked!

[PII036] Valar Morghulis

Jaqen H'ghar, the Faceless Man from Bravos, greeted you with "valar morghulis" (the High Valyrian for "all men must die"), for which you answered "valar dohaeris" ("all men must serve").

He was deep in thought, and after a moment, he looked at you with wide eyes and said, "I’ve been thinking, yes, thinking a lot. What happens when we remove things, yet still find meaning?"

Jaqen continued: "Imagine a word, yes? A perfectly good word. But what if we could remove certain letters — pluck them out, one by one — yet still find another word hidden within?"

The Problem

Write a function int substring(char key[], char str[]) that, given two strings key and str, return 1 if key can be found as a (non necessarily contiguous) substring in str, and 0 otherwise. This is the same as saying that is should return 1 if the key can be obtained from str if we remove zero or more letters from it.

For example, "omg" can be found in the string "oh_my_god" and "abc" can be found in "abracadabra".

Constraints

The following limits are guaranteed in all the test cases that will be given to your program:

1 ≤ |key| < 100       Length of the key
1 ≤ |str| < 100       Length of the string

Submission

You should submit a .c file containing the requested function, without any main function and without printing anything. You can however create additional methods, if you need them.

Mooshak will use the following code to link to your function, read the inputs and call your method, printing its result.

#include <stdio.h>
#include <string.h>

#define MAX_SIZE 100

int substring(char [], char []);

int main(void) {

  // Read amount of test cases
  int n;
  scanf("%d", &n);

  // Read n cases and for each call the substring function
  char key[MAX_SIZE], str[MAX_SIZE];
  for (int i=0; i<n; i++) {
    scanf("%s %s", key, str);
    printf("substring(\"%s\",\"%s\") = %d\n", key, str, substring(key, str));
  }
  
  return 0; 
}

Example Input Example Output
5
omg oh_my_god
abc abracadabra
my me_myself_and_irene
lol lllllooooo
no yes
substring("omg","oh_my_god") = 1
substring("abc","abracadabra") = 1
substring("my","me_myself_and_irene") = 1
substring("lol","lllllooooo") = 0
substring("no","yes") = 0

Programming II (CCINF1002)
DCC/FCUP - University of Porto