Question

In: Computer Science

A) Many test cases. For each case, the first line is the number N that indicates...

A) Many test cases.

For each case, the first line is the number N that indicates the amount of the students in the database.

Next to several N lines are the information of each student, include student ID, name, gender, and age.

And then will receive a number M that indicates there will be M search.

For each search line is an ID number, you need to compare to the database if there is any student with that ID. If yes, print ID, name, gender, and age of this student (if the ID is repeated, just print the previous one); if not, print "No Answer!".

You need to do this question by defining the data structure otherwise you can't real get the points.

Note: need can accept Chinese word! (take care of your array size)

Sample Input

4

1 Anna G 22

2 Teddy B 19

3 Joseph B 21

4 Rita G 22

2

1

5

2

20 阿王 男 16

23 阿美 女 15

1

23

Sample Output

1 Anna G 22

No Answer!

23 阿美 女 15


B)

Use stack to implement postfix arithmetic operation.

Input

Many test cases until EOF.

Each line is a postfix arithmetic operation formula.

There is no blank between the numbers, and the number only is 0-9.

Output

The result of each line.

But if the postfix arithmetic operation formula is wrong (it means you can't get the correct answer), please output "Input Error".

Sample Input

35+

3+5

63/14-*3+8-

Sample Output

8

Input Error

-11

C) There are several block stacks. The number of blocks for each stack may not be same, so your task is to move the block to let them be the same and calculate the minimum moves.

Example,

1 2 3

move stack 3 one block to the stack 1, so it will be:

2 2 2

Input

Many test cases.

For each case, first line is the number N(N<=50) of block stacks.

Next several N numbers are the number of blocks for each stack.

When N=0, the test is end.

Output

The case number and the minimum moves of each case. All the test are legal.

Sample Input

5

1 2 3 4 5

3

9 4 2

0

Sample Output

Set #1

The minimum number of moves is 3.

Set #2

The minimum number of moves is 4.

D)

Naming is important in the code. We always choose the relational vocabulary to name a variable. When we have two or more vocabularies to name, we are used to let the first letter of each vocabulary to be capitalized and connect all the vocabulary.

Take example, room number => RoomNuber sky color => SkyColor

Input

Many test cases until EOF.

Each line is many vocabularies.

Output

Naming result of each vocabulary.

Sample Input

aaaa bbbb cccc

ABCD BCDF FGHRTH

Sample Output

AaaaBbbbCccc

AbcdBcdfFghrth

Programming language: C++

Solutions

Expert Solution

Ans..(B)

#include<stdio.h>
 #include<ctype.h>


 # define MAXSTACK 100        /* for max size of stack */
 # define POSTFIXSIZE 100     /* define max number of charcters in postfix expression */

 /* declare stack and its top pointer to be used during postfix expression
        evaluation*/
 int stack[MAXSTACK];
 int top = -1 ;             /* because array index in C begins at 0 */
 /* can be do this initialization somewhere else */

 /* define push operation */
 void push(int item)
 {

         if(top >= MAXSTACK -1)
         {
                 printf("stack over flow");
                 return;
         }
         else
         {
                 top = top + 1 ;
                 stack[top]= item;
         }
 }

 /* define pop operation */
 int pop()
 {
         int item;
         if(top <0)
         {
                printf("stack under flow");
         }
         else
         {
                 item = stack[top];
                 top = top - 1;
                 return item;
         }
 }

 /* define function that is used to input postfix expression and to evaluate it */
 void EvalPostfix(char postfix[])
 {

        int i ;
        char ch;
        int val;
        int A, B ;


        /* evaluate postfix expression */
        for (i = 0 ; postfix[i] != ')'; i++)
        {
                ch = postfix[i];
                if (isdigit(ch))
                {
                        /* we saw an operand,push the digit onto stack
                        ch - '0' is used for getting digit rather than ASCII code of digit */
                        push(ch - '0');
                }
                else if (ch == '+' || ch == '-' || ch == '*' || ch == '/')
                {
                        /* we saw an operator
                        * pop top element A and next-to-top elemnet B
                        * from stack and compute B operator A
                        */
                        A = pop();
                        B = pop();

                        switch (ch) /* ch is an operator */
                        {
                                case '*':
                                val = B * A;
                                break;

                                case '/':
                                val = B / A;
                                break;

                                case '+':
                                val = B + A;
                                break;

                                case '-':
                                val = B - A;
                                break;
                        }

                        /* push the value obtained above onto the stack */
                        push(val);
                }
        }
        printf( " \n Result of expression evaluation : %d \n", pop()) ;
 }

 int main()
 {

        int i ;

        /* declare character array to store postfix expression */
        char postfix[POSTFIXSIZE];
        printf("ASSUMPTION: There are only four operators(*, /, +, -) in an expression and operand is single digit only.\n");
        printf( " \nEnter postfix expression,\npress right parenthesis ')' for end expression : ");

        /* take input of postfix expression from user */

        for (i = 0 ; i <= POSTFIXSIZE - 1 ; i++)
        {
                scanf("%c", &postfix[i]);

                if ( postfix[i] == ')' ) /* is there any way to eliminate this if */
                { break; } /* and break statement */
        }

        /* call function to evaluate postfix expression */

        EvalPostfix(postfix);
        
        return 0;

 }

Related Solutions

Cross-number problem (fill in the missing amounts in the cases below, each case is independent) Case...
Cross-number problem (fill in the missing amounts in the cases below, each case is independent) Case Units Sold Sales Variable Expenses Contribution Margin per unit Fixed Expenses Net Income 1 ? $100,000 ? 10 32,000 8,000 2 6,000 300,000 ? ? 100,000 (10,000) Case Sales Variable expenses Average contribution margin (percent) Fixed expenses Net Income (loss) 3 $500,000 ? 20 ? $7,000 4. ? ? 60 130,000 20,000
Cross-number problem (fill in the missing amounts in the cases below, each case is independent) Case...
Cross-number problem (fill in the missing amounts in the cases below, each case is independent) Case Units Sold Sales Variable Expenses Contribution Margin per unit Fixed Expenses Net Income 1 ? $100,000 ? 10 32,000 8,000 2 6,000 300,000 ? ? 100,000 (10,000) Case Sales Variable expenses Average contribution margin (percent) Fixed expenses Net Income (loss) 3 $500,000 ? 20 ? $7,000 4. ? ? 60 130,000 20,000
Design the Use Case Diagram and the test cases for Online Mobile Store Use Cases Phase...
Design the Use Case Diagram and the test cases for Online Mobile Store Use Cases Phase II
description 
 Example: Online Computer Store Requirement 1 – Laptops Requirement 2 - Desktops Requirement 3 - Mainframes Use Cases Testing phase 2 Requirement 1 - Laptops - Test case Requirement 2 - Desktops Requirement 3 - Mainframes
These questions can be approached from a number of angles, and in many cases, there is...
These questions can be approached from a number of angles, and in many cases, there is no single correct answer. All questions are of equal value. Question One How are bacterial endospores different from the cysts of protozoa? How are they alike? Question Two Discuss some of the ways in which bacteriophages might be used to treat bacterial diseases? What might be some disadvantages? Question Three Give some suggestions for treating anaerobic infections by manipulating the gas content. Question Four...
These questions can be approached from a number of angles, and in many cases, there is...
These questions can be approached from a number of angles, and in many cases, there is no single correct answer. All questions are of equal value. Question One How are bacterial endospores different from the cysts of protozoa? How are they alike? Question Two Discuss some of the ways in which bacteriophages might be used to treat bacterial diseases? What might be some disadvantages? Question Three Give some suggestions for treating anaerobic infections by manipulating the gas content. Question Four...
Determine the missing amounts in each of the following independent cases. Case A Case B Case...
Determine the missing amounts in each of the following independent cases. Case A Case B Case C Beginning inventory, raw material 98,000 7,500 Ending inventory, raw material 199,000 34,000 Purchases of raw material 295,000 274,000 Direct material used 235,000 323,000 Direct labor 395,000 72,000 Manufacturing overhead 595,000 99,000 Total manufacturing costs 1,135,000 1,130,000 222,000 Beginning inventory, work in process 89,000 79,000 Ending inventory, work in process 124,000 4,400 Cost of goods manufactured 1,088,000 225,000 Beginning inventory, finished goods 195,000 139,000...
CASE STUDY: THE CASE OF ROSA N.* In many parts of the world the kind of...
CASE STUDY: THE CASE OF ROSA N.* In many parts of the world the kind of blatant racism, sexism, and discrimination described in the denial section of this chapter is becoming less common. Two such places are The Netherlands and California, both of which have the reputation of being racially progressive and tolerant when compared to other European countries or U.S. states. People articulate the virtues of pluralism, deny the presence of racism in their communities, and condemn its presence...
Test the null hypothesis that the mean difference in the number of cases lost on appeal...
Test the null hypothesis that the mean difference in the number of cases lost on appeal for the two groups of judges is zero against the alternative hypothesis that the untrained judges lose more cases on appeal. Use an alpha level of .01. Judge Untrained Trained 1 3 0 2 1 3 3 2 4 4 7 4 5 5 2 6 4 5 7 6 1 8 2 1 9 7 0 10 5 6 11 3 4 12...
In Java: The n^th Harmonic number is the sum of the reciprocals of the first n...
In Java: The n^th Harmonic number is the sum of the reciprocals of the first n natural numbers: H(n) = 1+ 1/2 + 1/3 +1/4 +... +1/n Write a recursive method and an accompanying main method to compute the n^th Harmonic number. I have tried but get a blank and would really apreciate a fully explained code.
Consider an optimization model with a number of resource constraints. Each indicates that the amount of...
Consider an optimization model with a number of resource constraints. Each indicates that the amount of the resource used cannot exceed the amount available. Why is the shadow price of such a resource constraint always zero when the amount used in the optimal solution is less than the amount available?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT