✔ 最佳答案
我先講講loop比你聽,program 方面急唔急,later有時間先試下 ~
for loop 就係將一D會重複做幾次既野 group埋一齊做,例如
for i:= 1 to 10 do
write('*');
就係write10次*
有時我地會用到咁樣:
for i:= 1 to 5 do begin
for j:= 1 to 5 do write('*')
writeln;
end;
咁樣就係
先write 5 次*,再隔一行 <<<呢2個步驟做5次
2011-12-30 19:39:12 補充:
while loop 就係有一個條件,如果符合就做下面既野,如果唔符合就唔做
例如
while x<>1 do write('*')
就係當x 不等於1 ,就會write *
要做複雜小小就要加上begin end;
while x<> 1 do begin
write('*');
writeln;
write(x);
end;
2011-12-30 19:41:49 補充:
repeat loop 就係包住一group野,做左一次之後,再判斷再做唔做
例如
x:=0;
repeat
write('*');
x:=x+1;
until(x>10)
上面就會重複做write('*') 同x:=x+1 而當x>10(姐係11)就唔會再做
(注意,repeat loop 一定會做一次,而 while loop有機會一次都唔做)
2011-12-30 19:43:41 補充:
另外想問一問,您學了 procedure未?
2011-12-30 22:24:19 補充:
以下的program 只供參考,因為太多字(仲要分2次 = ="),唔係意見到發放~
自己睇下明唔明,唔明就問LA~
program password;
var keyword,abc,temp,q:string;
option,a,e:integer;
continue:char;
function password:string;
var j:integer;
i:char;
word:string;
flag:boolean;
begin
password:=keyword;
for i:= 'a' to 'z' do begin
flag:=true;
for j:= 1 to length(keyword) do begin
word:=copy(keyword,j,1);
if i=word then flag:=false;
end;
if flag then password:=password+i;
end;
end;
procedure encryption;
var plaintext,ciphertext,word,temp:string;
e,x,p:integer;
begin
ciphertext:='';
write('Enter plaintext:');
readln(plaintext);
temp:=plaintext;
plaintext:='';
for e:= 1 to length(temp) do begin
q:=copy(temp,e,1);
if (ord(temp[e]) < 97)
then plaintext:=plaintext+chr(ord(temp[e])+32)
else plaintext:=plaintext+q;
end;
for x:= 1 to length(plaintext) do begin
word:=copy(plaintext,x,1);
p:=pos(word,password);
ciphertext:=ciphertext+copy(abc,p,1);
end;
write('Ciphertext=',ciphertext);
writeln;
end;
procedure decryption;
var plaintext,ciphertext,word,temp:string;
b,c,e:integer;
begin
plaintext:='';
write('Enter ciphertext:');
readln(ciphertext);
temp:=ciphertext;
ciphertext:='';
for e:= 1 to length(temp) do begin
q:=copy(temp,e,1);
if (ord(temp[e]) < 97)
then ciphertext:=ciphertext+chr(ord(temp[e])+32)
else ciphertext:=ciphertext+q;
end;
for b:= 1 to length(ciphertext) do begin
word:=copy(ciphertext,b,1);
c:=pos(word,abc);
plaintext:=plaintext+copy(password,c,1);
end;
write('Plaintext=',plaintext);
writeln;
end;
begin
a:=0;
abc:='abcdefghijklmnopqrstuvwxyz';
write('Enter keyword:');
readln(keyword);
temp:=keyword;
keyword:='';
for e:= 1 to length(temp) do begin
q:=copy(temp,e,1);
if (ord(temp[e]) < 97)
then keyword:=keyword+chr(ord(temp[e])+32)
else keyword:=keyword+q;
end;
writeln(keyword);
repeat
a:=0;
writeln('Menu:');
writeln('1.Encryption');
writeln('2.Decryption');
writeln('3.Exit');
write('>');
2011-12-30 22:25:39 補充:
if option=1
then begin
encryption;
write('Do you want to continue(y/n)?');
readln(continue);
if continue='y' then a:=1;
end
2011-12-30 22:25:46 補充:
else if option=2
then begin
decryption;
write('Do you want to continue(y/n)?');
readln(continue);
if continue='y' then a:=1;
end
else exit;
until a<>1;
end.
2011-12-30 22:28:56 補充:
我想補充一點 . 都唔得,話太多字 = ="
,一定要係意見度發佈, sorry~
2011-12-31 19:22:21 補充:
I think the program has no problem since I can run it at home.I will send the file to you later.Anyway, if I know how to slove your problem,i will answer and you may send me a email to ask me~
2011-12-31 20:17:03 補充:
依家放緊假,唔緊要,later 要考試就唔得,考完試再問吧~
加油!