The current selected programming language is C. We emphasize the submission of a fully working code...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The current selected programming language is C. We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted, you cannot review this problem again. You can use printf() to debug your code. The printf() may not work in case of syntax/runtime error. The version of GCC being used is 5.5.0. There is a set of N jars. The jars contain differing numbers of chocolates. Some of the jars may be empty. Andrew may pick multiple jars but he may not pick any jar that is adjacent to a jar that he has already picked. Write an algorithm to calculate the maximum number of chocolates that Andrew may collect by picking jars. Input The first line of the input consists of an integer - choco_size, representing the number of jars of chocolates (N). The second line of the input consists of N space- separated integers- choco, representing the number of chocolates in each jar. Output Print an integer representing the maximum number of chocolates that Andrew may collect. Constraints 1 < choco_size <10³ -105 ≤ choco[i] ≤ 105; where i is representing the index of the jars of chocolate. Osi< choco_size Example Input: 6 5 30 99 60 5 10 Output: 114 Explanation Andrew picks from the 1st (5), 3rd (99), and 6th jars (10). Test Cases & Output 1 V/Header Files 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<stdbool.h> 6 7 /* only used in string related operations */ 8 typedef struct String string; struct String char *str; 9 10 - { 11 12 }; 13 14 char *input(FILE *fp, int size, int has_space) 15 { 16 17 18 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 51 52 - { 53 54 55 56 57 58 /* * 59 60 65 66 }; 73 74 75 76 77 78 ▾ 79 71 { 72 80 81 82 83 84 85 86 87 88 int actual size = 0; char *str = (char *)malloc(sizeof(char)* (size+actual_size)); char ch; if(has_space == 1) { 50 typedef struct array_single_int array_single_int; struct array_single_int while(EOF != (ch-fgetc (fp)) && ch != '\n') { str[actual size] = ch; actual size++; if(actual size >= size) str = realloc(str, sizeof (char)sactual_size); } else } Editor { } while (EOF != (ch-fgetc (fp)) && ch != '\n' && ch != ' ') { = } /* only used in string related operations */ 67 68 } 69 70 int main() */ 61 int maxNumOfChocolates (array_single_int choco) 62 - { 63 64 str[actual size] = ch; actual size++; if(actual size >= size) str = realloc(str,sizeof(char)*actual_size); { } actual size++; str realloc(str,sizeof(char)*actual_size); str[actual_size-1] = '\0'; return str; int *data; int size; int answer; // Write your code here return answer; array_single_int choco; //input for choco scanf("%d", &choco.size); choco.data = (int *)malloc (sizeof(int) * choco.size); for (int idx = 0; idx < choco.size; idx++) { scanf ("%d", &choco.data[idx]); } int result = maxNumOfChocolates (choco); printf("%d", result); return 0; The current selected programming language is C. We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted, you cannot review this problem again. You can use printf() to debug your code. The printf() may not work in case of syntax/runtime error. The version of GCC being used is 5.5.0. There is a set of N jars. The jars contain differing numbers of chocolates. Some of the jars may be empty. Andrew may pick multiple jars but he may not pick any jar that is adjacent to a jar that he has already picked. Write an algorithm to calculate the maximum number of chocolates that Andrew may collect by picking jars. Input The first line of the input consists of an integer - choco_size, representing the number of jars of chocolates (N). The second line of the input consists of N space- separated integers- choco, representing the number of chocolates in each jar. Output Print an integer representing the maximum number of chocolates that Andrew may collect. Constraints 1 < choco_size <10³ -105 ≤ choco[i] ≤ 105; where i is representing the index of the jars of chocolate. Osi< choco_size Example Input: 6 5 30 99 60 5 10 Output: 114 Explanation Andrew picks from the 1st (5), 3rd (99), and 6th jars (10). Test Cases & Output 1 V/Header Files 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<stdbool.h> 6 7 /* only used in string related operations */ 8 typedef struct String string; struct String char *str; 9 10 - { 11 12 }; 13 14 char *input(FILE *fp, int size, int has_space) 15 { 16 17 18 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 51 52 - { 53 54 55 56 57 58 /* * 59 60 65 66 }; 73 74 75 76 77 78 ▾ 79 71 { 72 80 81 82 83 84 85 86 87 88 int actual size = 0; char *str = (char *)malloc(sizeof(char)* (size+actual_size)); char ch; if(has_space == 1) { 50 typedef struct array_single_int array_single_int; struct array_single_int while(EOF != (ch-fgetc (fp)) && ch != '\n') { str[actual_size] = ch; actual size++; if(actual size >= size) str = realloc(str, sizeof(char)sactual_size); } else } Editor } /* only used in string related operations */ { } while(EOF != (ch-fgetc (fp)) && ch != '\n' && ch != ' ') { str[actual_size] = ch; actual size++; if(actual size >= size) str = realloc(str,sizeof(char)*actual_size); = */ 61 int maxNumOfChocolates (array_single_int choco) 62 - { 63 64 67 68 } 69 70 int main() { } actual size++; str realloc(str, sizeof(char)*actual_size); str[actual_size-1] = '\0'; return str; int *data; int size; int answer; // Write your code here return answer; array_single_int choco; //input for choco scanf("%d", &choco.size); choco.data = (int *)malloc(sizeof(int) choco.size); for (int idx = 0; idx < choco.size; idx++) { scanf("%d", &choco.data[idx]); } int result = maxNumOfChocolates (choco); printf("%d", result); return 0; The current selected programming language is C. We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted, you cannot review this problem again. You can use printf() to debug your code. The printf() may not work in case of syntax/runtime error. The version of GCC being used is 5.5.0. There is a set of N jars. The jars contain differing numbers of chocolates. Some of the jars may be empty. Andrew may pick multiple jars but he may not pick any jar that is adjacent to a jar that he has already picked. Write an algorithm to calculate the maximum number of chocolates that Andrew may collect by picking jars. Input The first line of the input consists of an integer - choco_size, representing the number of jars of chocolates (N). The second line of the input consists of N space- separated integers- choco, representing the number of chocolates in each jar. Output Print an integer representing the maximum number of chocolates that Andrew may collect. Constraints 1 < choco_size <10³ -105 ≤ choco[i] ≤ 105; where i is representing the index of the jars of chocolate. Osi< choco_size Example Input: 6 5 30 99 60 5 10 Output: 114 Explanation Andrew picks from the 1st (5), 3rd (99), and 6th jars (10). Test Cases & Output 1 V/Header Files 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<stdbool.h> 6 7 /* only used in string related operations */ 8 typedef struct String string; struct String char *str; 9 10 - { 11 12 }; 13 14 char *input(FILE *fp, int size, int has_space) 15 { 16 17 18 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 51 52 - { 53 54 55 56 57 58 /* * 59 60 65 66 }; 73 74 75 76 77 78 ▾ 79 71 { 72 80 81 82 83 84 85 86 87 88 int actual size = 0; char *str = (char *)malloc(sizeof(char)* (size+actual_size)); char ch; if(has_space == 1) { 50 typedef struct array_single_int array_single_int; struct array_single_int while(EOF != (ch-fgetc (fp)) && ch != '\n') { str[actual size] = ch; actual size++; if(actual size >= size) str = realloc(str, sizeof (char)sactual_size); } else } Editor { } while (EOF != (ch-fgetc (fp)) && ch != '\n' && ch != ' ') { = } /* only used in string related operations */ 67 68 } 69 70 int main() */ 61 int maxNumOfChocolates (array_single_int choco) 62 - { 63 64 str[actual size] = ch; actual size++; if(actual size >= size) str = realloc(str,sizeof(char)*actual_size); { } actual size++; str realloc(str,sizeof(char)*actual_size); str[actual_size-1] = '\0'; return str; int *data; int size; int answer; // Write your code here return answer; array_single_int choco; //input for choco scanf("%d", &choco.size); choco.data = (int *)malloc (sizeof(int) * choco.size); for (int idx = 0; idx < choco.size; idx++) { scanf ("%d", &choco.data[idx]); } int result = maxNumOfChocolates (choco); printf("%d", result); return 0; The current selected programming language is C. We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted, you cannot review this problem again. You can use printf() to debug your code. The printf() may not work in case of syntax/runtime error. The version of GCC being used is 5.5.0. There is a set of N jars. The jars contain differing numbers of chocolates. Some of the jars may be empty. Andrew may pick multiple jars but he may not pick any jar that is adjacent to a jar that he has already picked. Write an algorithm to calculate the maximum number of chocolates that Andrew may collect by picking jars. Input The first line of the input consists of an integer - choco_size, representing the number of jars of chocolates (N). The second line of the input consists of N space- separated integers- choco, representing the number of chocolates in each jar. Output Print an integer representing the maximum number of chocolates that Andrew may collect. Constraints 1 < choco_size <10³ -105 ≤ choco[i] ≤ 105; where i is representing the index of the jars of chocolate. Osi< choco_size Example Input: 6 5 30 99 60 5 10 Output: 114 Explanation Andrew picks from the 1st (5), 3rd (99), and 6th jars (10). Test Cases & Output 1 V/Header Files 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<stdbool.h> 6 7 /* only used in string related operations */ 8 typedef struct String string; struct String char *str; 9 10 - { 11 12 }; 13 14 char *input(FILE *fp, int size, int has_space) 15 { 16 17 18 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 51 52 - { 53 54 55 56 57 58 /* * 59 60 65 66 }; 73 74 75 76 77 78 ▾ 79 71 { 72 80 81 82 83 84 85 86 87 88 int actual size = 0; char *str = (char *)malloc(sizeof(char)* (size+actual_size)); char ch; if(has_space == 1) { 50 typedef struct array_single_int array_single_int; struct array_single_int while(EOF != (ch-fgetc (fp)) && ch != '\n') { str[actual_size] = ch; actual size++; if(actual size >= size) str = realloc(str, sizeof(char)sactual_size); } else } Editor } /* only used in string related operations */ { } while(EOF != (ch-fgetc (fp)) && ch != '\n' && ch != ' ') { str[actual_size] = ch; actual size++; if(actual size >= size) str = realloc(str,sizeof(char)*actual_size); = */ 61 int maxNumOfChocolates (array_single_int choco) 62 - { 63 64 67 68 } 69 70 int main() { } actual size++; str realloc(str, sizeof(char)*actual_size); str[actual_size-1] = '\0'; return str; int *data; int size; int answer; // Write your code here return answer; array_single_int choco; //input for choco scanf("%d", &choco.size); choco.data = (int *)malloc(sizeof(int) choco.size); for (int idx = 0; idx < choco.size; idx++) { scanf("%d", &choco.data[idx]); } int result = maxNumOfChocolates (choco); printf("%d", result); return 0;
Expert Answer:
Answer rating: 100% (QA)
Here is an algorithm to calculate the maximum number of chocolates that Andrew may collect by pickin... View the full answer
Related Book For
Data Analysis and Decision Making
ISBN: 978-0538476126
4th edition
Authors: Christian Albright, Wayne Winston, Christopher Zappe
Posted Date:
Students also viewed these electrical engineering questions
-
The current selected programming language is Java. We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted, you cannot review this problem again....
-
Effective persuasive techniques in one culture may not work in another culture. Do a web search on intercultural communication and locate a topic that is important for technical communication. Find...
-
We can sort a given set of n numbers by first building a binary search tree containing these numbers (using TREE-INSERT repeatedly to insert the numbers one by one) and then printing the numbers by...
-
Four wooden beams, each of length 2a, are nailed together at their midpoints to form the support system shown. Assuming that only vertical forces are exerted at the connections, determine the...
-
1. There is asymmetric information in the used-car market because _________ (buyers/sellers) cannot distinguish between lemons and plums but _________ (buyers/sellers) can. 2. The supply curve for...
-
Janyce, a single taxpayer, has AGI of $125,000 and paid the following taxes this year. Calculate how much Janyce can deduct for taxes as an itemized deduction this year. State income tax...
-
For testing H0 : 1 = 2 versus H1: 1 < 2, we observe s1 = 0.9, s2 = 1.5, n1 = 16, and n2 = 11. Test at the significance level = 0.01. a. Find the critical value. b. Do you reject H0?
-
Jinny Buffett recently retired as a flight attendant and is interested in opening a fitness center and health spa exclusively for women in Grand Cayman, where she resides. After careful study, she is...
-
2] Based on the KFC case reading, explain what types of advertising KFC used and why KFC used the types of advertising chosen for their advertising campaign. [3] Based on the case reading, explain...
-
1. What type of attitude scale is used by the ACSI if any? 2. What type of attitude study might you design if you were the consultant? 3. How would you use results from this approach to diagnose...
-
Evaluate tan (4) without using a calculator Evaluate 4 sec (20) - 4 tan (20) without using a calculator Evaluate cos(30) sin(60) without using a calculator Find the amplitude of f(x) = 9 sin (3x+)...
-
The Cutting Department of Arizona Manufacturing has the following production and cost data for July. Production Costs 1. Transferred out 12,000 units. Beginning work in process $ -0- 2. Started 1,500...
-
Interest rates on 4-year Treasury securities are currently 6.0%, while 6-year Treasury securities yield 7.85%. If the pure expectations theory is correct, what does the market believe that 2-year...
-
Date The following transactions occurred for the month of May. Units Cost Total Sales Price 1-May Beginning Balance 80 12 $960 2-May Purchase 85 15 $1,275 3-May Purchase 65 11 $715 10-May Sale 90 $30...
-
Company A has net sales of $250 million and costs of $190 million. The depreciation expense is $20 million, and the interest paid is $8.5 million. Assume the tax rate is 25 percent. Company B has the...
-
For the 2023 taxation year, Sundal Ltd. has net income of $235,000. Included in this amount is foreign business income of $48,000 of which the foreign income taxes of $7,200 were withheld. Sundal is...
-
Portland Pizzeria makes the best pies in Maine. They are working on their Direct Labor budget for the upcoming year and would like to know how much direct labor dollars they will be spending in...
-
You are planning to purchase your first home five years from today. The required down payment will be $50,000. You currently have $20,000. but you plan to contribute $500 each quarter to a special...
-
There is a lot of concern about salary compression in universities. This is the effect of paying huge salaries to attract newly-minted Ph.D. graduates to university tenure-track positions and not...
-
African Americans in a St. Louis suburb sued the city claiming they were discriminated against in schoolteacher hiring. Of the citys population, 5.7% were African American; of 405 teachers in the...
-
The file P11_47.xlsx contains the quarterly revenues (in millions of dollars) of a utility company for a seven-year period. The goal is to use these data to build a multiple regression model that can...
-
The smooth vane shown diverts the open stream of fluid of crosssectional area \(A\), mass density \(ho\), and velocity \(v\). (a) Determine the force components \(R\) and \(F\) required to hold the...
-
For the moving vane of Sample Problem 4/6, determine the optimum speed \(u\) of the vane for the generation of maximum power by the action of the fluid on the vane. Problem 4/6, The smooth vane shown...
-
The offset nozzle has a discharge area \(A\) at \(B\) and an inlet area \(A_{0}\) at \(C\). A liquid enters the nozzle at a static gage pressure \(p\) through the fixed pipe and issues from the...
Study smarter with the SolutionInn App