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 ""GoodA**fter***Noo*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: "GoodAf". Hàng đợi nhả theo nguyên tắc vào trước ra trước, và mỗi dấu sao nhả đúng một ký tự nên độ dài kết quả bằng số dấu sao: thông điệp có hai dấu sao sau GoodA, ba dấu sao sau fter và một dấu sao sau Noo, tổng 2 + 3 + 1 = 6, vậy kết quả phải dài 6 ký tự. Chạy tay: nạp G, o, o, d, A; hai dấu sao nhả G rồi o; nạp f, t, e, r; ba dấu sao nhả o, d, A; nạp N, o, o; dấu sao cuối nhả f; ký tự n còn lại chỉ được nạp vào. Ghép theo thứ tự nhả được G, o, o, d, A, f. Vì vậy "Adoretfo" sai vì nó dài 8 ký tự và lại nhả theo chiều ngược, lấy ký tự vào sau cùng trước, tức hành vi của ngăn xếp; "odAfter" sai vì nó dài 7 ký tự và bỏ hai ký tự đầu G, o mà hai dấu sao đầu tiên buộc phải nhả; "GoodA" sai vì chỉ có 5 ký tự, nó bỏ sót lần nhả của dấu sao thứ sáu, lúc đó đầu hàng đang là f.
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