Need help with my program, read from a text into many variables.

Hello, i have to make this program, but i still haven't finished it and i need some help. This is what i have to do.
Make a program in Pascal that after has read a text with a list of nums., it will return the numb. of the nums that appear less than one times in the text.

The text that will be read from the program should be like that.

In the first line there are two nums. seperated by a space, n and m. N is the number of nums that exist, like if the text contains the numbers 1,2,3,4, n is 4 (1..n).
M is how many lines follow.
Every line has a couple of nums, a,b, (1=<a=<n), (1=<b=<n) (a<>b)
a and b are separated by a space.

The file that the program will make will have written on it a num., that says how many nyms are appeared less than two tims in the text.

All the nums. are Integer.

0=<p=<n

i've made the following program, but it only reads the first line of the text. Anyone that can help me? The deadline is almost ended. Thanks in advance.
My code is the following.
Program thefinalp;

Uses SysUtils;

Var
f:Text;
m,d:Integer;
n:Char;
c:String[1];

a,e:array of integer;
LowArr:Integer;
HighArr:Integer;
ArrayLen:Integer;
i:Integer;

begin
Assign(f,'finalp.txt');
Reset(f);

repeat
Read (f,n);
Write(n);
until (n=' ');

Read(f,c);
Write(c);

while not SeekEoln(f) do
begin
read(f,d);
Write(d);
End;
Readln;
Writeln;

StrToIntDef(n,m);

setlength(a,m);
LowArr:=Low(a);
HighArr:=High(a);
ArrayLen:=Length(a);

setlength(e,m);
LowArr:=Low(e);
HighArr:=High(e);
ArrayLen:=Length(e);

for i:= LowArr to HighArr do

begin

repeat
Read (f,a[i]);
Write(a[i]);
until (n=' ');

Read(f,c);
Write(c);

while not SeekEoln(f) do
begin
read(f,e[i]);
Write(e[i]);
End;
Readln;
Writeln;

End;
Readln;
End.

I've made the code after that, the program is how to put into variables all the nums.
I'm a beginner so if anyone could give me an example, would help a lot.

domes.in domes.out
6 7 2
2 4
4 1
3 5
4 3
1 3

Comments

  • ough I can't check on a computer right now but maybe you can use an array 'A' to know how many times a number appears. And I don't know the limit of the numbers so you should use Longint for all vars

    Assign(f,'finalp.inp');
    Reset(f);
    Readln(f,n,m);
    Fillchar(A,n,0);
    For i:=1 to m do
     Begin
       Readln(f,u,v);
       Inc(a[u]);
       Inc(a[v]);
     End;
    Close(f);
    For i:=1 to n do
      If a[i]>=2 then inc(count);

    Fillchar({array's name},{size of array},{value}); used to set value for all the array.
    Count is the answer you need. Maybe it's too late now :(
  • Oh you should also put in one more line : count:=0; after line 11

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion