Algorithm and Programming
55 questions · IT Passport
There is a series of numbered boxes stacked as shown in the figure below. The operations described in the table below are performed in the sequence of operations 1 through 4. When the operation 4 is completed, which of the following shows the status of the stacked boxes?
Fig.
Table
The data is exchanged between variable A and variable B. When variable TMP is used to temporarily store data, which of the following is the procedure for exchanging data correctly? Here, “x ← y” represents that the data of “x” is replaced with the data of “y”.
There exist four (4) states numbered 1 through 4. The four (4) states are connected as shown in the figure below, and the state transition occurs in a clockwise or counter-clockwise direction.
If the current state is 1, which of the following is the state that is reached after the procedure below is performed twice?
[Procedure]
The number of the current state is multiplied by 11, and the result is divided by 3. The process below is performed based on the remainder of the division.
- •When the remainder is 0, a transition to the next state occurs in the clockwise direction.
- •When the remainder is 1, a transition to the next state occurs in the counter-clockwise direction.
- •When the remainder is 2, a transition to the second state occurs in the clockwise direction.
The procedure findBanknotes outputs the number of 10,000 and 1,000 banknotes required to represent a specified amount of money, in that order, ensuring the minimum number of banknotes is used. The argument amount passed to the procedure must be a non-negative multiple of 1,000. If it is not, the procedure outputs an error message. Which of the following is the correct combination of answers to be inserted into A and B in the program?
A hollow square is an n × n matrix whose first and last rows along with the first and last columns are filled with stars (“*”), where n denotes an integer. All other positions inside the matrix other than the borders are filled with spaces. If n is 5, the hollow square is shown as below.
The procedure printHollowSquare prints a hollow square based on the value of n. Which of the following is the correct answer to be inserted into blank in the program? Here, the value n is at least 3 and is passed as an argument to the procedure.
Which of the following is a term for a list of instructions to a computer that are written in a human-readable programming language?
The procedure calculateElectricBill receives electricity usage that accepts the units (non-negative value) and returns the amount of electricity bills. The pricing structure is given as: For the first 100 units, the cost is $10 per unit. Any units exceeding 100 are charged at $15 per unit. Which of the following is an appropriate piece of code to be inserted into blank in the program?
A program uses loops to display results based on whether the cycle numbers are odd or even. The execution result of the program is shown below.
Which of the following is an appropriate combination of pieces of code to be inserted into A through C in the program?
In the data structure called a queue that is suitable for performing first-in first-out (FIFO) processing, values are stored in the order of “8”, “1”, “6”, and “3”, and then two (2) values are removed consecutively. Which of the following is the last value that is removed?
As shown in Figure 1, there is a box that generates two (2) numerical values B1 and B2 when two (2) positive integers A1 and A2 are entered. B1 has the same value as A2, and B2 is the remainder of A1 divided by A2. In Figure 2, when two (2) boxes are connected, and 49 is entered as A1 and 11 is entered as A2 in the left box, what is the value of B2 generated from the right box?
Figure 1
Figure 2
At a certain company, employees get a medical allowance equal to 5% of their monthly base salary in addition to their monthly base salary. If the total of the monthly base salary and medical allowance is more than 5,000, a 20% tax is deducted from the total. In the program below, the function calculateTotalSal receives the monthly base salary as an argument and returns the monthly total salary after tax deduction. Which of the following is the correct combination of pieces of code to be inserted into A and B in the program? Here, the monthly base salary is a multiple of 100.
Which of the following is the appropriate way for extracting data from a stack that stores multiple data?
In the program below, the function subTotal receives an integer array inputarr as an argument, returns an array arr in which the sum of all elements of original array inputarr up to that location is stored in the same location. Which of the following is the correct combination of pieces of code to be inserted into A and B in the program. Here, the size of the array inputarr is greater than 1, and elements outside the bounds of the array must not be accessed, and the array index starts at 1.
The function calGrade receives the student’s score and returns the grade. The score is an integer. If the score is greater than or equal to 80, the function calGrade returns “A”; if the score is between 65 and 79, it returns “B”; between 50 and 64, it returns “C”; and otherwise, it returns “Fail.” Which of the following is an appropriate piece of code to be inserted in blank in the program?
The procedure described below is sequentially performed for two (2) variables x and y, starting with step (1). When the procedure is completed, what is the resulting value of x?
There is a device that stacks products from the bottom to the top, and removes the products sequentially from the top. There are only two (2) operations for this device.
Nothing is stacked at the start, and three (3) products arrive in the order A, B, then C. If only one (1) device is used, when the products are removed with POP operations, which of the following is an impossible order of removal?
The program performs circular left shifting on the array elements. For example, after circular left shifting, the initial array {1, 2, 3, 4, 5} becomes {2, 3, 4, 5, 1}. Which of the following is an appropriate combination of pieces of code to be inserted in A and B in the program?
Which of the following is the appropriate reason for using a style sheet in the creation of a website?
Which of the following is an appropriate description concerning machine language?
A power company charges electricity bill shown in the table below.
Function computeBill receives the number of units used per month as an argument and returns the electricity bill in 1/100 dollars. Which of the following is an appropriate combination of pieces of code to be inserted in A and B in the program?
In a markup language, with the purpose of displaying on a screen and printing, it is possible to directly embed not only the document content, but also the document structure and layout information, and the character font and size information. Which of the following is classified into such a markup language?
The procedure draw receives a non-negative integer number n for input. When the value of n is 6, the procedure outputs the six lines shown below. Which of the following is an appropriate combination of pieces of code to be inserted in A and B in the program?
There is a program that displays text in accordance with the specifications below. When the original text described below is displayed, in what point size does the program display the underlined character string? Here, the first character of the original text is displayed in 10 points.
[Specifications]
The characters between <B> and </B> are displayed one point larger than the preceding character.
The characters between <S> and </S> are displayed one point smaller than the preceding character.
Each of <B> </B> and <S> </S> must be used as a pair, and both of them can be nested with each other.
[Original text]
The system administrator promotes and implements <B>department-level<B> or
<S>group-level</S> computerization</B> from a user’s <S>standpoint</S>.</B>
Which of the following is an appropriate description concerning the Java language?
Algorithms are important when a computer is used. Which of the following is an appropriate explanation of an algorithm?
As shown in Figure 1, there is a processing unit which reads two positive integer input values A1 and A2, and then writes two integer output values B1 and B2. B1 is equal to A2, and B2 is the remainder of A1 divided by A2. In Figure 2, two processing units with the same function as the above are connected in series. When A1=15 and A2=6 are given to the left-hand unit in Figure 2, what is the output value of B1 for the right-hand unit?
Figure 1
Figure 2
When the process that is shown in the flowchart is ended, which of the following is the value of x?
Note: The condition of the either boundary of the iteration indicates the end condition.
In a queue, three (3) elements 33, 27, and 12 are enqueued in this order. After the element 45 is enqueued to this queue, two (2) elements are retrieved (or dequeued). Which of the following is the second element to be retrieved?
Which of the following represents a processing procedure of a program graphically?
Which of the following is the method for describing the logical structure of a sentence in XML?
A stack is a first-in last-out data structure. By using a stack, a device receives data from the right side, changes their order and sends them to the left side, as shown in the figure below. There are three (3) types of operations available on the device, as described below.
When the device receives X, Y, and Z in this order from the right side, which of the following is the order in which the device cannot send them to the left side even if the operations (1) to (3) are combined?
Among the program control structures, which of the following is classified as a “while-type” loop structure?
Among the items A through C described below about programming languages, which of the following is the list that contains all of the appropriate items?
Which of the following is an appropriate description concerning the usage of HTML (Hyper Text Markup Language) tags?
In the data structure called a queue that is suitable for performing first-in first-out (FIFO) processing, values are stored in the order of “8”, “1”, “6”, and “3”, and then a value is removed twice continuously. Which of the following is the value that is obtained by the second removal?
A markup language specifies the character color according to the “Syntax and meaning of the markup language definition section” below. When an element (parent) contains another element (child), the child inherits the parent’s specifications, but priority is given to the child-specific specifications if the child and the parent have different values specified for the same attribute. When the text in the “Example” below is displayed according to this rule, which of the following is the appropriate display attribute for the underlined character string? Here, “<strong>character string</strong>” specifies the character string to be emphasized, for example by using bold font.
Which of the following is an appropriate explanation of an algorithm that is used on a computer?
The procedure sort receives an integer-type array with 2 or more elements as the argument numberArray, and outputs the result of sorting its elements in ascending order. To check the operation of the procedure sort, the value of j and all the elements of workArray are output in the middle of the processing. When the array numberArray is {3, 5, 1, 2, 4} and the procedure sort is called as sort(, which of the following is the output of all the elements of workArray immediately after the value of j is output as 3? Here, the array index starts at 1.
The function isPrime returns true as the return value if the positive integer given as its argument is a prime number, and false if it is not a prime number. For example, when the function isPrime is called as isPrime(, the return value is true. Which of the following is the appropriate combination of words to be inserted into A and B in the program?
There is a robot that, by being programmed, can raise and lower a pen, move straight ahead, and change direction by turning clockwise. A program that makes this robot draw a regular hexagon with sides of 1 m was created. Which of the following is the appropriate combination of values to be inserted into A and B in the regular hexagon drawing program below?
[Regular hexagon drawing program]
Which of the following is the output when the procedure calcMod3 is called?
When a sequence of data consisting of four (4) elements is sorted in ascending order by repeating the procedure below, how many times is the series of steps (1) through (3) executed until the sorting is completed? Here, at first, the whole sequence of data is the target of sorting.
Sequence of data: [27, 42, 33, 12]
[Procedure]
The function calculateAmountOfPrize receives the improvement amount and the reduction period in the effects of a business improvement as improvement and period respectively, and returns the prize amount as the return value. There were a business improvement with an improvement amount of 200,000 yen and a reduction period of 3 days, and a business improvement with an improvement amount of 50,000 yen and a reduction period of 14 days. How many yen is the total of these two prize amounts? Here, the values of the improvement amount and the reduction period are each 0 or more.
The function convert is a program that converts an integer-type array into a string according to a certain rule. When the function convert is called as convert(, which of the following is the value of the argument arrayInput for which the return value is “AABAB”? Here, the number of elements in arrayInput is 1 or more, and the array index starts at 1.
The function binaryToInteger receives, as the argument binaryStr, a value that represents an unsigned binary number of one or more digits as a character string, and returns the result of converting the value into an integer as the return value. For example, when it receives “100” as the argument, it returns 4. Which of the following is the appropriate combination of pieces of code to be inserted into A and B in the program?
The procedure printArray sorts the elements of the array integerArray and outputs them. Which of the following is the output when the procedure printArray is called? Here, the array index starts at 1.
The function sigma receives a positive integer as the argument max, and returns the sum of the integers from 1 to max as the return value. Which of the following is the appropriate piece of code to be inserted into A in the program?
Which of the following is an appropriate description concerning search algorithms when data stored in an array is searched?
The function checkDigit receives, as the argument, the integer-type array originalDigit in which the digits of each place of a 9-digit decimal integer are stored in order from the highest place, and returns, as the return value, the check digit calculated by the following procedure. Which of the following is the appropriate piece of code to be inserted into A in the program? Here, the array index starts at 1.
[Procedure]
originalDigit.(2)If the total value is greater than 9, total the digits of each place when the total value is expressed as a decimal integer. Repeat this operation until the total value becomes 9 or less.(3)Use the value obtained in (2) as the check digit.Which of the following is the appropriate combination of words to be inserted into blanks A and B in the following description concerning data formats that are used when information collected by an IoT device is sent to an IoT server?
The A format is a data format that indicates the separation of data with delimiter characters such as commas, and the B format is a markup language and is a data format in which the logical structure of data can be described by using tags.
The functions calcX and calcY perform calculations by using the argument inData, and make the results their return values. When the function calcX was called as calcX(, the value of the variable num of the function calcX changed as 1→3→7→13, and the return value was 13. When the function calcY was called as calcY(, the value of the variable num of the function calcY changed as 1→5→13→25, and the return value was 25. Which of the following is the appropriate combination of words to be inserted into A and B in the programs?
In the processing shown in Flowchart X, the value of variable i changed as 1 → 3 → 7 → 13, and in the processing shown in Flowchart Y, the value of variable i changed as 1 → 5 → 13 → 25. Which of the following is the appropriate combination of words to be inserted into blanks A and B in the figures?
(Note) The repetition specification of a loop limit shows variable name: initial value, increment, final value.