1. Logic: Scope Congruence of Strings In order to define scope congruence of any two strings,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
It looks like you are sharing screenshots of text related to an exercise or explanation about Scope ... View the full answer
Related Book For
Project Management A Systems Approach to Planning Scheduling and Controlling
ISBN: 978-0470278703
10th Edition
Authors: Harold Kerzner
Posted Date:
Students also viewed these programming questions
-
Im not sure we should lay out $ 250,000 for that automated welding machine, said Jim Alder, president of the Superior Equipment Company. Thats a lot of money, and it would cost us $ 80,000 for...
-
Any time we conduct a survey, we must take care to avoid undercoverage. Suppose we plan to select 500 names from the city phone book, call their homes between noon and 4 P.M., and interview whoever...
-
How many strings of five ASCII characters contain the character @ ("at" sign) at least once?
-
An abc-sequence balanced three-phase wye-connected source supplies power to a balanced wye-connected load. The line impedance per phase is 1 + j10, and the load impedance per phase is 20 + j20. If...
-
Who is considered a knowledge worker? Will you have a career as a knowledge worker? Explain.
-
Figure P35.4 shows an apparatus used to measure the speed distribution of gas molecules. It consists of two slotted rotating disks separated by a distance d, with the slots displaced by the angle &....
-
William Stem filed an action against Gary Braden, seeking to rescind a contract for the sale of an automobile and to obtain the return of the purchase price plus interest. The trial court granted...
-
Inventory information for Part 311 of Monique Aaron Corp. discloses the following information for the month of June. June 1 Balance 300 units .... @ $10 11 Purchased 800 units .... @ $12 20 Purchased...
-
Oil having a density of 921 kg/m floats on water. A rectangular block of wood 4.41 cm high and with a density of 963 kg/m floats partly in the oil and partly in the water. The oil completely covers...
-
At the beginning of the year, Anna began a calendar-year business and placed in service the following assets during the year: Date Acquired 1/30 Cost Asset Basis $ 58,000 $ 62,000 $ 105,000 $ 440,000...
-
In describing how he worked toward the goals of becoming literate and knowledgeable, Malcolm X touches on a variety of important issues related to developing thinking and language abilities. We can...
-
Identify trends in the development of enterprise architecture for digital transformation.
-
Declare an array variable for the MMC named Employee1 of type MMCEmployee1 that can store 100 numbers of employees. Then, store the following data at index 77: employeeID 2299 employeePosition -...
-
1 You own a Sweet making business and you need to buy a new mixing machine. You have two choices, one of which is expected to last three years and the other five. They have differing costs and...
-
Distribution Received: During the second year, the taxpayer received $5,000, but importantly, this money was not from the business's profits. Hypothetical Scenario: If this $5,000 distribution had...
-
An investor is considering the following investment options, which are not mutually exclusive. The cash flows are as follows: t 10 11 2 3 4-6 7-8 t 1 - 10000 -5000 0 1 -1000 6000 6000 2 -15000 -10000...
-
Choc-lattes Corp. earned $5.00 per share in 2006, and paid a dividend of $2.00 per share. If it earns $5.50 in 2007. Follows a constant payout ratio policy, its dividend will be?
-
An auto-parts manufacturer is considering establishing an engineering computing center. This center will be equipped with three engineering workstations each of which would cost $25,000 and have a...
-
Pricing out a customers request for proposal is a trade-off between time, cost, and accuracy. If time and money are not an issue, then we could determine a very accurate bid. But if the company is...
-
What is the correct way for a project manager to invite line managers to attend team meetings?
-
Explain how the relative intensity of a conflict can vary as a function of: a. Getting closer to the actual constraints b. Having only two constraints instead of three (i.e., time and performance,...
-
Show that the vector potentials given in Eq. (27.1) imply the magnetic fields given in Eq. (27.2) by evaluating \(\boldsymbol{B}=\boldsymbol{abla} \times \boldsymbol{A}\) in the cylindrical...
-
Prove the result of Eq. (26.10) that a path-dependent representation of a gauge group is sensitive to a gauge transformation only at the endpoints of the path.
-
Use Stokes' theorem [Eq. (27.5)] to prove that Eq. (27.4) leads to Eq. (27.6). Data from Eq. 27.4 Data from Eq. 27.5 Data from Eq. 27.6 = z ) ); A dr. - SA dr) = f A dr.
Study smarter with the SolutionInn App