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**Morn**i***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: "gnoG". Vòng lặp đọc xâu chỉ đẩy ký tự thường vào ngăn xếp, còn mỗi dấu sao lấy một phần tử ra mà không in; phần in nằm ở vòng lặp sau, lấy 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; Morn vào thành G, o, M, o, r, n, hai dấu sao lấy n và r nên còn G, o, M, o; i vào rồi ba dấu sao lấy i, o, M nên còn G, o; n và g vào thành G, o, n, g. Vòng in lấy từ đỉnh được g, n, o, G. "gnoM" giữ M trên đỉnh, nghĩa là chỉ dùng hai trong ba dấu sao đứng sau chữ i. "gnro" giữ lại r, nhưng r đã bị lấy ra bởi dấu sao ngay sau khúc Morn. "Gong" là đọc ngăn xếp từ đáy lên đỉnh, tức in theo kiểu vào trước ra trước của hàng đợi thay vì 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