Consider the following pseudocode: declare a queue 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 dequeue and write the dequeued character to the screen
else
enqueue the character into the queue
}What is written to the screen for the input ""Go*odA**fter**No**o***n" ?
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: "GoodAfterN". Hàng đợi lấy ra theo đúng thứ tự đưa vào, nên mỗi dấu sao in ra chữ cái chưa in nào vào sớm nhất. Dãy nhập có mười dấu sao nên in ra mười chữ. Chữ cái vào lần lượt là G, o, o, d, A, f, t, e, r, N, o, o, n; mười lần dequeue lấy đúng mười chữ đầu của dãy đó, cho GoodAfterN, còn o, o, n vẫn nằm trong hàng đợi khi dãy nhập hết. "GoodAfter" sai vì nó chỉ có chín chữ, tức đếm thiếu một dấu sao trong cụm ba sao cuối. "oodAfteroo" sai vì nó bỏ chữ G đầu tiên, nhưng G vào trước nên phải là chữ ra trước nhất. "oAdoretfoo" sai vì thứ tự đó đảo lộn chữ vào trước ra sau, giống hành vi của ngăn xếp chứ không phải hàng đợi.
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