Consider the following pseudocode: declare a stack of characters
5 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 poped character to the screen What is written to the screen for the input "FileComp**ress*ion***" ?
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: "seroCeliF". Dấu sao ở đây chỉ lấy bỏ phần tử trên đỉnh mà không in; chỉ 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 F, i, l, e, C, o, m, p; hai dấu sao bỏ p rồi m. Nạp r, e, s, s; một dấu sao bỏ một chữ s. Nạp i, o, n; ba dấu sao bỏ n, o, i. Ngăn xếp còn F, i, l, e, C, o, r, e, s nên in ngược cho đủ chín ký tự. Chuỗi "seroCeli" rơi mất F ở cuối, nhưng F là ký tự nạp đầu tiên nên nó nằm dưới cùng và được in sau chót. Chuỗi "seroCelFi" đổi chỗ hai ký tự cuối, trong khi i nạp ngay sau F nên i phải ra trước F. Chuỗi "seroCeliFn" chen thêm n vào cuối, mà n đã bị một trong ba dấu sao cuối lấy bỏ. Chuỗi "Filreion" liệt kê theo chiều nạp vào chứ không theo chiều lấy ra, lại còn chứa i, o, n là ba ký tự đã bị loại bỏ.
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