I wrote this little program in pascal:
program split;
var s,p,q,r,t:longint;
a: array of string;
x,y:string;
begin
read (s);
setlength (a,s);
read (p);
readln (a[0]);
for q:=1 to s-1 do
a[q]:=a[0];
for q:=1 to p do
begin
read (x);
if x='SPLIT' then
begin
read (r);
x:=a[r - 1];
read (y);
for t:=0 to r-2 do
if a[t]=a[r - 1] then a[t]:=y;
read (y);
for t:=r-2 to s do
if a[t]=a[r - 1] then a[t]:=y;
end;
if x='QUERY' then
begin
read (t);
writeln (a[t]);
end;
end;
end.
and it wont even go to the loop, it just ends. Can you help?
I know how it works in theory too. but it doesnt seem to work when i want to input the size of the array.
var a:array of string;
x,y:integer;
b:string;
begin
readln (x);
setlength (a,x);
(The next part of the program should search input from user and fill these strings)
Readln (b);
for y:=0 to x-1 do
a[x]:=b;
end.
This is the simplest example of what im trying to do, and i still dont have a slightest idea why it doesnt.