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 "GoodM**orn****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: "Mdnroon". Mỗi dấu sao lấy phần tử trên đỉnh ngăn xếp rồi in ngay, nên thứ tự in ngược thứ tự nạp. Nạp G, o, o, d, M; hai dấu sao in M rồi d, còn lại G, o, o. Nạp o, r, n; bốn dấu sao in n, r, o rồi o, còn lại G, o. Nạp i, n; một dấu sao in n, còn lại G, o, i. Nạp g rồi hết chuỗi, nên bảy dấu sao cho đúng bảy ký tự. Chuỗi "Mdnrono" đổi chỗ hai ký tự cuối, nhưng sau khi bốn dấu sao đã vét tới o thì lần nạp i, n đặt n lên đỉnh, nên dấu sao cuối phải in n chứ không phải o. Chuỗi "MdnrooG" kết thúc bằng G, mà G nạp đầu tiên nên nằm dưới cùng và không thể ra khi trên nó vẫn còn o với n. Chuỗi "Mdonroo" in o ở vị trí thứ ba, trong khi ngay sau hai lần in đầu thì đỉnh ngăn xếp là n của lần nạp o, r, n.
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