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 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**in***g" ?
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: "donrnio". Khác biến thể in ở cuối, ở đây mỗi dấu sao lấy ký tự ở đỉnh ngăn xếp và in ngay, còn sau khi đọc hết từ thì không có vòng xả, nên ký tự còn lại trong ngăn xếp không bao giờ xuất hiện. Chạy tay theo đúng thứ tự ký tự của từ: nạp G, o, o, d, hai dấu sao in d rồi o; nạp M, o, r, n, hai dấu sao in n rồi r; nạp i, n, ba dấu sao in n, i rồi o (chữ o đẩy vào ngay sau M); cuối cùng nạp g nhưng không còn dấu sao nên g cùng G, o, M nằm lại trong ngăn xếp. Màn hình nhận d, o, n, r, n, i, o, đúng bảy ký tự cho bảy dấu sao. "donrnoo" in o trước r trong nhóm M, o, r, n, trái nguyên tắc vào sau ra trước vì r được đẩy vào sau o. "donrniM" và "donrniG" lầm ở dấu sao thứ bảy: lúc đó đỉnh ngăn xếp là chữ o đẩy vào sau M, còn M nằm dưới nó và G nằm dưới cùng.
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