Consider the following pseudocode: declare a stack of characters
4 phương ánCó giải thích
while(there are more characters in the word to read){read a character if a character is '*' then pop the stack
else
push the character into the stack
}
while(the stack is not empty)pop and write the poped character to the screen What is written to the screen for the input "Good**Mor*ni***ng" ?
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "gnMoG". Mỗi dấu sao chỉ lấy một phần tử ra khỏi ngăn xếp mà không in gì; phần in chỉ xảy ra ở vòng lặp cuối, lấy lần lượt từ đỉnh xuống đáy. Chạy tay: Good vào thành G, o, o, d; hai dấu sao lấy d và o nên còn G, o; Mor vào thành G, o, M, o, r; một dấu sao lấy r nên còn G, o, M, o; n và i vào thành G, o, M, o, n, i; ba dấu sao lấy i, n, o nên còn G, o, M; n và g vào thành G, o, M, n, g. In từ đỉnh được g, n, M, o, G. "gnMoo" để chữ o ở đáy, nhưng đáy ngăn xếp là G vì G được đẩy vào đầu tiên và không dấu sao nào lấy tới nó. "gnoMo" đổi chỗ M với o, trái thứ tự đẩy vào là o trước rồi M. "GoMng" là đọc từ đáy lên đỉnh, tức in theo kiểu vào trước ra trước chứ không phải vào sau ra trước của ngăn xếp.
Cùng phần 2
Select the statement that is most correct.
Which of the following applications may not use a stack?Có lời giảiCâu hỏiConsider the following pseudocode:
declare a stack of characters
while(there are more characters in the word to read)
{read a character
if a character is '*' then
pop the stack
else
push the character into the stack
}
while(the stack is not empty)
pop and write the poped character to the screen
What is written to the screen for the input "Good**Morn**in***g" ?Có lời giảiCâu hỏiConsider the following pseudocode:
declare a stack of characters
while(there are more characters in the word to read)
{read a character
if a character is '*' then
pop and write the poped character to the screen
else
push the character into the stack
}
What is written to the screen for the input "Good**Morn**i***ng" ?Có lời giảiCâu hỏiCả 51 câu của chủ đề51 câu
Xuất hiện trong 1 bộ đề
Đi tiếp từ đây