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 "Good**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: "doringi". Ở đoạn mã này dấu sao vừa lấy phần tử ra khỏi ngăn xếp vừa in ngay phần tử đó, nên chuỗi in ra là dãy phần tử bị lấy ra. Chạy tay: Good vào rồi hai dấu sao in d và o; Mor 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 d, o, r, i, n, g, i. "donrioo" đặt n trước r, nhưng r đã bị lấy ra bởi dấu sao đứng ngay sau khúc Mor, lúc đó n còn chưa được đẩy vào. "donrioG" mắc cùng chỗ đảo đó và còn kết bằng G, trong khi G nằm tận đáy ngăn xếp và không dấu sao nào lấy tới nó. "donriMG" in thêm cả M và G, hai ký tự vẫn còn nằm trong ngăn xếp khi xâu đã đọc hết, mà đoạn mã này không có vòng in phần còn lại. "GooMorni" là thứ tự các ký tự được đẩy vào chứ không phải thứ tự bị lấy ra.
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