比赛 20121121 评测结果 EEEEEEEEEE
题目名称 谁拿了最多奖学金 最终得分 0
用户昵称 digital-T 运行时间 0.002 s
代码语言 Pascal 内存使用 0.17 MiB
提交时间 2012-11-21 19:55:51
显示代码纯文本
var
key,st1:string;
a,b,i,j,k:integer;
keykey:array[1..100]of integer;
counta,countb:array[1..26,1..26]of char;
begin
assign(input,'vigenere.in');reset(input);
assign(output,'vigenere.out');rewrite(output);
readln(key);
read(st1);
//____________________________________________
for i:=1 to 26 do
 for j:=1 to 26 do
  begin
   if (j-i+27)mod 26=0 then k:=26 else k:=(j-i+27)mod 26;
   counta[i,j]:=chr(k+96);
  end;
//____________________________________________
for i:=1 to 26 do
 for j:=1 to 26 do
  begin
   if (j-i+27)mod 26=0 then k:=26 else k:=(j-i+27)mod 26;
   countb[i,j]:=chr(k+64);
  end;
//____________________________________________
a:=length(key);
b:=length(st1);
for i:=1 to a do if ord(key[i])>96 then keykey[i]:=ord(key[i])-96
                                   else keykey[i]:=ord(key[i])-64;
//________________________________________________________________
k:=0;
for i:=1 to b do
 begin
  inc(k);
  if k>a then k:=k mod a;
  if ord(st1[i])>96 then st1[i]:=counta[keykey[k],ord(st1[i])-96]
                    else st1[i]:=countb[keykey[k],ord(st1[i])-64];
 end;
//________________________________________________________________
write(st1);
close(input);
close(output);
end.