Consider the following pseudocode: declare a stack of characters
5 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 and write the poped character to the screen
else
push the character into the stack
}What is written to the screen for the input "Go*od**Mor*ni**ng*Si*r" ?
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: "odoringi". Ở đoạn mã này mỗi dấu sao lấy một phần tử ra khỏi ngăn xếp và in ngay, nên chuỗi in ra chính là dãy phần tử bị lấy ra theo thứ tự. Chạy tay: G, o vào rồi dấu sao in o; o, d vào rồi hai dấu sao in d và o; M, o, r vào rồi dấu sao in r; n, i vào rồi hai dấu sao in i và n; n, g vào rồi dấu sao in g; S, i vào rồi dấu sao in i. Ghép lại được o, d, o, r, i, n, g, i. "donrnoo" là một dãy đọc ngược, nó chỉ đúng nếu chương trình giữ ký tự lại rồi in một lượt ở cuối. "donrniM" cũng đọc ngược và còn in cả M, mà M vẫn nằm trong ngăn xếp khi xâu đã hết. "donrniG" đọc ngược và kết bằng G, trong khi G nằm tận đáy và không dấu sao nào lấy tới nó. "odoringS" khớp bảy ký tự đầu nhưng kết bằng S, còn dấu sao cuối lấy ra i vì i đã đè lên S và đang ở đỉnh.
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