- #1
doktorwho
- 181
- 6
Homework Statement
For our final test preparation we were given a few problems to write and this is one of them:
I would be very grateful if you could help me find the easiest way to solve it.
Homework Equations
3. The Attempt at a Solution [/B]
First let me tell you my plan for writing this program so you can see if my idea is good. So let's say everything was nicely inputted and i have to do the encription now. My idea is this: I read the first element of the key sequence. Let's say its 3. Then since i know its 3 my first coloumn of the matrix (since its first element) goes to the third place (swap the third and the first). So now my first coloumn is read third. Wherever i find the element 1 in the key that matrix coloumn is my first: ( let's say its on the last position of the key, then my last coloumn is the first). When i read it i read it in the standard way. Does this seem good to you?
Here is the code till now and the place i got stuck at:
Code:
program firstprogram;
const
MAX=10;
type
matrix=array[1..MAX,1..MAX] of char;
key=array[1..MAX] of integer;
var
a:matrix;
b:key;
c:char;
setchar:set of char;
n,i:integer;
begin
writeln('Enter the number of key elements');
readln(n);
if (n<5) or (n>MAX) then
exit;
writeln('Enter the key elements');
for i:=1 to n do
begin
readln(b[i]);
if (b[i]<1) or (b[i]>n) then
exit;
end;
setchar:=['a'..'z']; {i need this to check if the matrix input is a charachter and not something else}
{This is the place i need to ask the user to input the matrix with the original text,
it should type it in one line and i should divide it's charachters into places in the matrix..
i don't know how to do this, could you help me? And possible without me having to
take a long time to come up with it couse its kinda averagly urgent :), thanks}
end.