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 "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: "Adretfoo". 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 luôn ngược thứ tự nạp. Nạp G, o, o, d, A; hai dấu sao in A rồi d, ngăn xếp còn G, o, o. Nạp f, t, e, r; năm dấu sao in r, e, t, f rồi o, ngăn xếp còn G, o. Nạp N, o, o; một dấu sao in o, ngăn xếp còn G, o, N, o. Sau đó nạp n và hết chuỗi nên không in thêm, tổng cộng tám ký tự ứng với tám dấu sao. Chuỗi "Adretfdo" thay ký tự thứ bảy bằng d, nhưng d đã bị in từ lần lấy ra thứ hai nên không thể ra lần nữa. Chuỗi "Adretfon" kết thúc bằng n, mà n là ký tự nạp sau cùng và chuỗi vào đã hết trước khi có thêm dấu sao nào để đẩy nó ra. Chuỗi "Adoretoo" đặt o ngay sau hai ký tự đầu, trong khi lúc ấy ngăn xếp vừa nhận f, t, e, r nên ba lần lấy ra kế tiếp phải cho r, e, t.
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