?? ch3 應用題參考答案.mht
字號:
style=3D"FONT-FAMILY: =CB=CE=CC=E5">1</SPAN><SPAN style=3D"FONT-FAMILY: =
=CB=CE=CC=E5">=A1=A2 =
=D3=D0=C8=FD=B8=F6=B2=A2=B7=A2=BD=F8=B3=CC=A3=BA<SPAN=20
lang=3DEN-US>R =
</SPAN>=B8=BA=D4=F0=B4=D3=CA=E4=C8=EB=C9=E8=B1=B8=B6=C1=C8=EB=D0=C5=CF=A2=
=BF=E9=A3=AC<SPAN lang=3DEN-US>M =
</SPAN>=B8=BA=D4=F0=B6=D4=D0=C5=CF=A2=BF=E9=BC=D3=B9=A4=B4=A6=C0=ED=A3=BB=
<SPAN=20
lang=3DEN-US>P =
</SPAN>=B8=BA=D4=F0=B4=F2=D3=A1=CA=E4=B3=F6=D0=C5=CF=A2=BF=E9=A1=A3=BD=F1=
=CC=E1=B9=A9=A3=BB<SPAN lang=3DEN-US><o:p></o:p></SPAN></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN lang=3DEN-US =
style=3D"FONT-FAMILY: =CB=CE=CC=E5"><o:p> </o:p></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN lang=3DEN-US =
style=3D"FONT-FAMILY: =CB=CE=CC=E5">l </SPAN><SPAN style=3D"FONT-FAMILY: =
=CB=CE=CC=E5">=A3=A9=D2=BB=B8=F6=BB=BA=B3=E5=C7=F8=A3=AC=BF=C9=B7=C5=D6=C3=
<SPAN=20
lang=3DEN-US>K </SPAN>=B8=F6=D0=C5=CF=A2=BF=E9=A3=BB<SPAN =
lang=3DEN-US><o:p></o:p></SPAN></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN lang=3DEN-US =
style=3D"FONT-FAMILY: =CB=CE=CC=E5"><o:p> </o:p></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN lang=3DEN-US =
style=3D"FONT-FAMILY: =CB=CE=CC=E5">2 </SPAN><SPAN style=3D"FONT-FAMILY: =
=CB=CE=CC=E5">=A3=A9=B6=FE=B8=F6=BB=BA=B3=E5=C7=F8=A3=AC=C3=BF=B8=F6=BF=C9=
=B7=C5=D6=C3<SPAN=20
lang=3DEN-US>K </SPAN>=B8=F6=D0=C5=CF=A2=BF=E9=A3=BB<SPAN =
lang=3DEN-US><o:p></o:p></SPAN></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN lang=3DEN-US =
style=3D"FONT-FAMILY: =CB=CE=CC=E5"><o:p> </o:p></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN=20
style=3D"FONT-FAMILY: =
=CB=CE=CC=E5">=CA=D4=D3=C3=D0=C5=BA=C5=C1=BF=BA=CD<SPAN lang=3DEN-US>P =
</SPAN>=A1=A2<SPAN lang=3DEN-US>V=20
</SPAN>=B2=D9=D7=F7=D0=B4=B3=F6=C8=FD=B8=F6=BD=F8=B3=CC=D5=FD=C8=B7=B9=A4=
=D7=F7=B5=C4=C1=F7=B3=CC=A1=A3<SPAN =
lang=3DEN-US><BR></SPAN>=B4=F0=A3=BA<SPAN lang=3DEN-US><BR>1 )=20
var B : array [ 0 , k-1 ] of item ; <BR><SPAN=20
style=3D"mso-spacerun: =
yes"> =20
</SPAN>sread : semaPhore : =3D k ; <BR><SPAN=20
style=3D"mso-spacerun: =
yes"> =20
</SPAN>smanage : semaPhore : =3D 0 ; <BR><SPAN=20
style=3D"mso-spacerun: =
yes"> =20
</SPAN>swrite : semaphore : =3D 0 ; <BR><SPAN=20
style=3D"mso-spacerun: =
yes"> =20
</SPAN>rptr : integer : =3D O ; <BR><SPAN=20
style=3D"mso-spacerun: =
yes"> =20
</SPAN>mptr : integer : =3D O ; <BR><SPAN=20
style=3D"mso-spacerun: =
yes"> =20
</SPAN>wptr </SPAN>=A3=BA<SPAN lang=3DEN-US>integer : =3D 0 ; <BR><SPAN=20
style=3D"mso-spacerun: =
yes"> =20
</SPAN>x : item<BR><SPAN=20
style=3D"mso-spacerun: yes"> =
</SPAN>cobegin=20
<BR>process reader ;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; =20
</SPAN><SPAN style=3D"mso-spacerun: yes"> </SPAN>process manager ; =
<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; </SPAN>process=20
writer ; <BR>begin <SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; &nb=
sp; </SPAN>begin=20
<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; &nb=
sp; </SPAN>begin=20
<BR>LI : read a message intox ; <SPAN=20
style=3D"mso-spacerun: =
yes"> </SPAN>L2=20
: P ( smanage ) ;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; =20
</SPAN>L3 : P ( swnte ) ;<o:p></o:p></SPAN></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN lang=3DEN-US =
style=3D"FONT-FAMILY: =CB=CE=CC=E5"><SPAN style=3D"mso-spacerun: =
yes"> </SPAN>P ( sread )=20
;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; =20
</SPAN>x:=3DB[mptr];<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; &nb=
sp; =20
</SPAN><SPAN=20
style=3D"mso-spacerun: =
yes"> </SPAN>x:=3DB[swrite];<o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN lang=3DEN-US =
style=3D"FONT-FAMILY: =CB=CE=CC=E5">B[rptr]:=3Dx;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; &nb=
sp; =20
</SPAN>mptr:=3D(mptr+1) mod k;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; =20
</SPAN>wptr:=3D(wptr+1) mod k;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN lang=3DEN-US =
style=3D"FONT-FAMILY: =CB=CE=CC=E5">Rptr:=3D(rptr+1) mod k;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; =20
</SPAN>manage the message in x;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp;=20
</SPAN>V(sread);<o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN lang=3DEN-US =
style=3D"FONT-FAMILY: =CB=CE=CC=E5">V(smanage);<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; &nb=
sp; =20
</SPAN>B[mptr]:=3Dx;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp;=20
</SPAN><SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; </SPAN>print=20
the message in x;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN lang=3DEN-US =
style=3D"FONT-FAMILY: =CB=CE=CC=E5">Goto<SPAN style=3D"mso-spacerun: =
yes"> =20
</SPAN>L1;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; &nb=
sp; =20
</SPAN>V(swrite);<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; &nb=
sp; =20
</SPAN>goto L3;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN lang=3DEN-US =
style=3D"FONT-FAMILY: =CB=CE=CC=E5">End;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; &nb=
sp; =20
</SPAN>goto L2;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; &nb=
sp; =20
</SPAN>end;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"LAYOUT-GRID-MODE: char; TEXT-INDENT: 194.25pt; =
mso-char-indent-count: 18.5"><SPAN=20
lang=3DEN-US style=3D"FONT-FAMILY: =
=CB=CE=CC=E5">End;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN lang=3DEN-US =
style=3D"FONT-FAMILY: =CB=CE=CC=E5">coend<BR>2 ) var A , B :array [ 0 , =
k -l ] of item ;=20
<BR>sPut1 : semaphore:=3Dk; <BR>SPut2: <SPAN=20
style=3D"mso-spacerun: yes"> </SPAN>semaPhore:=3Dk; <BR>sget1 : =
semaPhore : =3D 0=20
; <BR>sget2 : semaphore : =3D 0 ; <BR>put1 </SPAN><SPAN=20
style=3D"FONT-FAMILY: =CB=CE=CC=E5">=A3=BA<SPAN lang=3DEN-US>integer =
</SPAN>=A3=BA<SPAN lang=3DEN-US>=3DO ;=20
<BR>put2</SPAN>=A3=BA<SPAN lang=3DEN-US>integer : =3D 0 ; <BR>get1 =
</SPAN>=A3=BA<SPAN=20
lang=3DEN-US>integer </SPAN>=A3=BA<SPAN lang=3DEN-US>=3DO ; <BR>get2 : =
integer : =3D O ;=20
<BR>cobegin <BR>process reader ;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; =20
</SPAN><SPAN style=3D"mso-spacerun: yes"> </SPAN>processn =
manager;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; =20
</SPAN><SPAN style=3D"mso-spacerun: yes"> </SPAN>process Writer ;=20
<o:p></o:p></SPAN></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN lang=3DEN-US =
style=3D"FONT-FAMILY: =CB=CE=CC=E5">begin <SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; &nb=
sp; </SPAN>begin=20
<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; &nb=
sp; </SPAN><SPAN=20
style=3D"mso-spacerun: =
yes"> </SPAN>begin=20
<BR>Ll : read a message into x ; <SPAN=20
style=3D"mso-spacerun: =
yes"> </SPAN>L2 :=20
P ( sgetl ) ;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; =20
</SPAN><SPAN style=3D"mso-spacerun: yes"> </SPAN>L3 : P ( sgetZ ) ; =
<BR>P (=20
SPut1 ) ;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; =20
</SPAN><SPAN style=3D"mso-spacerun: yes"> </SPAN>x : =3D A [ get1] =
;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; &nb=
sp;=20
</SPAN>x : =3D B [get2]; <o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN lang=3DEN-US =
style=3D"FONT-FAMILY: =CB=CE=CC=E5">A [put1]:=3Dx ;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; =20
</SPAN><SPAN style=3D"mso-spacerun: yes"> </SPAN>get1 </SPAN><SPAN=20
style=3D"FONT-FAMILY: =CB=CE=CC=E5">=A3=BA<SPAN lang=3DEN-US>(get1+1 ) =
mod k ; <SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; </SPAN>get2:=3D</SPAN>=A3=A8<SPAN=20
lang=3DEN-US>get2 + l ) mod k ;<o:p></o:p></SPAN></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN lang=3DEN-US =
style=3D"FONT-FAMILY: =CB=CE=CC=E5">Put1:=3D(put1+1) mod k;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; =20
</SPAN>V(sput1);<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; &nb=
sp; =20
</SPAN>V(sput2);<o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN lang=3DEN-US =
style=3D"FONT-FAMILY: =CB=CE=CC=E5">V(sget1);<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; &nb=
sp; =20
</SPAN>manage the message into x;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; =20
</SPAN>print the message in x;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"LAYOUT-GRID-MODE: char"><SPAN lang=3DEN-US =
style=3D"FONT-FAMILY: =CB=CE=CC=E5">Goto L1;<SPAN=20
style=3D"mso-spacerun: =
yes"> &n=
bsp; &nb=
sp; =20
</SPAN>P(sput2);<SPAN=20
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -