Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Logic: Scope Congruence of Strings In order to define scope congruence of any two strings, we will first define: - Scoped String -
1. Logic: Scope Congruence of Strings In order to define scope congruence of any two strings, we will first define: - Scoped String - Scope Rank Then we will define how to compute scope congruence between two strings. Scoped String A scoped string here is defined using the parenthesis '{' and '}'. All spaces within the string are ignored and string can have malformed scope, meaning a mismatching parenthesis. This means every '{' must accompany a subsequent '} to form a pair in order to not be qualified as well-formed. All white space characters within the string are ignored and the string otherwise should contain lower case characters [a..z] only. The only other allowed characters are the curly parenthesis. See constraint summary below to be able to take care of these cases. A valid scoped string can be: a{bc (def} {Im{ emc} } st} A fully contained substring instance includes all contiguous characters except parenthesis and space characters. In above example the following fully contained substrings exist: bc . def Im . emc 333 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 1> #in 41 42 43 44 45 46 47 48 49 50 /* * * T * * * * Fo * ch * * * *cha Test Results n left ALL 0 2 3 4 5 6 7 8 9 10 11 Scope Rank The scope rank of a fully contained substring is defined by the depth of the nesting of the scope. For instance in above example the following scopes apply: a bc def Im E st emc st substring 0 Constraints 1 The number on first line > 0 2 2 3 1 Scope Congruence Two stringssi and s are said to be scope congruent if every fully contained substring of si has the same scope rank as the identical fully contained substring of sk if the identical substring does exist in sk, and vice-versa. In other words fully contained substrings that are not common to si and s are ignored. We only compare the scope ranks of the substrings that are common to both si and Sk. scope rank Input Format The first line contains the number of input strings following that line. This is followed by an even number of lines, where first 2 lines are the first pair, the second two lines are the second pair and so on. So each pair comprises two lines. This is because in order to compute scope congruence you need to compare two strings in a pair. The first line of an input pair refers to si and the second line of input pair refers to sk. There are no blank lines. 38 39 40 41 42 43 44 45 46 67 47 29 30 31 32 33 34 35 36 37 48 49 50 22223 1> #inc Info C 19 20 24 25 26 27 28 21 /* * * * * * * C * * To *For * cha *TI *TH */ *} * * char Test Results 3m left ALL 2 3 4 5 6 7 00 8 9 10 11 Sk- Input Format The first line contains the number of input strings following that line. This is followed by an even number of lines, where first 2 lines are the first pair, the second two lines are the second pair and so on. So each pair comprises two lines. This is because in order to compute scope congruence you need to compare two strings in a pair. The first line of an input pair refers to s and the second line of input pair refers to sk. There are no blank lines. Constraints The number on first line > 0 String should contain lower case [a..z], space characters or '(' and }'. For all substrings, the scope rank < 10 Length of string in each pair < 40 No mismatching '(' and ')' parenthesis and every '' must have a subsequent '}' to complete the pair. Output Format For each pair of scoped strings sand s, write one line in output that has the value of either "true" or "false" or -1 if the constraints are not satisfied. Sample Input 6 a(bc (def) (Im{ emc} } st) c(bc (def) (xs (emc)) Ikd} a(bc (def) (Im{ emc) } st) c(bc {{def)} (xs (emc) } st} a(bc $ (def) (Im{emc} } st} c{bc (df) (xs ( emc) } st) Sample Output true false -1 Info 5 1> #inc 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 A M Test Dr /* * * Cc * /* *Th * Th */ * n * To * * For * cha * * } * char My No mismatching' and ' parenthesis and every '(' must have a subsequent 'y' to complete the pair. Output Format For each pair of scoped strings si and SK, write one line in output that has the value of either "true" or "false" or -1 if the constraints are not satisfied. Sample Input 6 a{bc (def) {Im{ emc} } st} c{bc {def} (xs {emc} } lkd} a{bc (def) {Im{ emc} } st} c{bc {{def)} (xs {emc} } st} a{bc ${def} {Im{emc)} } st} c{bc {df)} (xs {emc} } st} Sample Output true false -1 Explanation In the first pair, "bc", "def" and "emc" are the common fully contained substrings and the scope ranks of these match as shown in the table in beginning of the example, hence we output "true". In the second pair, the scope ranks of all common fully contained substrings is same except "def". It's scope rank is 2 in si and 3 in Sk, hence we output "false". In the third pair, we encounter a '$' character in si and hence output -1. 64444 ww 47 48 23 24 25 26 27 28 29 33 34 35 36 37 38 39 40 41 42 43 44 45 49 50 30 2333 31 * * * * * 1 * * Test Resul 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 4 45 45 44 46 47 48 49 50 /* * Complete the scope_congruent function below. * * The function is expected to return a STRING_ARRAY. *The function accepts STRING_ARRAY input_str as parameter. */ /* * To return the string array from the function, you should: Store the size of the array to be returned in the result_count variable - Allocate the array statically or dynamically * For example, * char** return_string_array_using_static_allocation (int* result_count) { * * * * *result_count = 5; static char* a[5] = {"static", "allocation", "of", "string", "array"}; return a; * * char** return_string_array_using dynamic_allocation (int* result_count) { *result_count = 5; char* a malloc (5 sizeof(char*)); for (int i = 0; i < 5; i++) { } * Test Results *(a + 1) = malloc (20 sizeof(char)); *(a + 0) = "dynamic"; Custom Input * 9 9 1 2 14 5 16 7 48 49 50 51 52 53 * For example, * char** * *result_count = 5; static char* a[5] = {"static", "allocation", "of", "string", "array"}; * return_string_array_using_static_allocation (int* result_count) { return a; * * char** return_string_array_using_dynamic_allocation (int* result_count) { *result_count = 5; char** a = malloc (5 sizeof (char*)); for (int i = 0; i < 5;i++) { } *(a+i)= malloc (20 sizeof (char)); * (a + 0) = "dynamic"; *(a + 1) = "allocation"; * (a + 2) = "of"; * (a + 3) = "string"; * (a + 4) = "array"; 54 55 56 57 58 59 60 61 62 } 63 64 int main () - return a; Test Results * */ char** scope_congruent (int input_str_count, char** input_str, int* result_count) { Custom Input
Step by Step Solution
There are 3 Steps involved in it
Step: 1
It looks like you are sharing screenshots of text related to an exercise or explanation about Scope ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started