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 the stack
else
push the character into the stack
}
while(the stack is not empty)pop and write the popped character to the screen 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: "gioG". Ở đoạn mã này dấu sao chỉ lấy bỏ phần tử trên đỉnh mà không in; chỉ sau khi đọc hết chuỗi mới lấy ra lần lượt và in, nên kết quả là phần còn lại đọc ngược. Nạp G, o, o, d, M; hai dấu sao bỏ M rồi d. Nạp o, r, n; bốn dấu sao bỏ n, r, o rồi o. Nạp i, n; một dấu sao bỏ n. Nạp g và hết chuỗi, ngăn xếp còn G, o, i, g nên in ngược từ đỉnh xuống. Chuỗi "gioM" kết thúc bằng M, mà M đã bị dấu sao thứ nhất lấy bỏ nên không còn trong ngăn xếp. Chuỗi "giod" kết thúc bằng d, cũng là ký tự đã bị dấu sao thứ hai lấy bỏ. Chuỗi "Goig" liệt kê theo đúng chiều nạp vào, trong khi vòng lặp cuối lấy từ đỉnh nên phần tử nạp sau cùng là g phải ra trước và G ra sau chó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