为什么读入是死循环?

P1914 小书童——凯撒密码

黎明时空几何 @ 2016-08-24 19:24:18

var
  n,i:longint;
  str,str1:array[1..10000] of char;
  temp:array[1..1000] of longint;
begin
  readln(n);
  i:=1;
  while str[i])<>' ' do begin
    read(str[i]);
    i:=i+1;
  end;
  for i:=1 to i do begin
    temp[i]:=ord(str[i]);
    temp[i]:=temp[i]+n;
    if temp[i]>122 then temp[i]:=temp[i]-26;
    str1[i]:=chr(temp[i]);
  end;
  for i:=1 to i do write(str1[i]);
  writeln;
end.

by yuhengtong222 @ 2016-08-25 08:17:57

因为读入的数中没有空格


by 三车闹士 @ 2016-08-26 10:32:20

因为for i:=1 to i do


by 张瑞祥的pascal @ 2016-09-09 20:05:28

因为 readln(n);

i:=1;

while str[i])<>' ' do begin

(还没有读入str串)


by syszs @ 2016-09-16 21:01:59

var
  st:string;
  l,i,n:longint;
begin
  readln(n);
  readln(st);
  l:=length(st);
  for i:=1 to l do begin
                   st[i]:=chr(ord(st[i])+n);
                   if st[i]>'z' then st[i]:=chr(ord(st[i])-26);
                   end;
  writeln(st);
end.

by syszs @ 2016-09-16 21:02:48

应该是这样


by jxjjxj @ 2016-12-16 18:01:31

var a,i:longint;
    s:string;
begin
  readln(a);
  read(s);
  for i:=1 to length(s) do
  begin
    s[i]:=chr(ord(s[i])+a);
    if s[i]>'z' then s[i]:=chr(ord(s[i])-26);
  end;
  write(s);
end.

by jxjjxj @ 2016-12-16 18:02:09

读入中不会有‘ ’


|