Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Uses crt;
- type
- elem = record
- data:string[25];
- next:^elem;
- end;
- var
- tail,buf,head: ^elem;
- n:integer;
- info:string[25];
- i:integer;
- procedure add(var head,tail:^elem;info:string[25]);
- begin
- if head = nil then
- begin
- new(head);
- head^.data:=info;
- head^.next:=nil;
- tail := head;
- //AddFirst(head,tail,info);
- end
- else
- begin
- new(tail^.next);
- tail:=tail^.next;
- tail^.next:=nil;
- end;
- tail^.data := info;
- end;
- procedure print(tail: ^elem);
- var i:^elem;
- begin
- i := tail;
- while i <> nil do
- begin
- writeln(i^.data);
- i:=i^.next;
- end;
- writeln;
- end;
- function getElemById(var head: ^elem;index:integer):^elem;
- var i:^elem;
- count:integer;
- begin
- i := head;
- count := 1;
- while (i <> nil) and (count < index) do
- begin
- i:=i^.next;
- inc(count);
- end;
- Result := i;
- end;
- procedure sortirovka(var head,tail:^elem);
- var
- i,j,err,year1,k,year2,count:integer;
- sex,p : char;
- buf:string[25];
- begin
- i:=1;
- while(i<=10) do
- begin
- //val(copy(mas[i],20,4),year,err);
- if(getElemById(head,i)^.data[24]='P') and (getElemById(head,i)^.data[25]='M') then
- //if (mas[i][24]='P') and (mas[i][25]='M') then
- begin
- buf := getElemById(head,i)^.data;
- //buf := mas[i];
- for j:=i downto 2 do
- begin
- getElemById(head,j)^.data := getElemById(head,j-1)^.data;
- //mas[j] := mas[j-1];
- end;
- //mas[1] := buf;
- getElemById(head,1)^.data := buf;
- inc(count);
- end;
- inc(i);
- //writeln(year);
- end;
- for i:=1 to count-1 do
- begin
- for j:= i+1 to count do
- begin
- //getElemById(head,i)^.data
- val(copy(getElemById(head,i)^.data,20,4),year1,err);
- val(copy(getElemById(head,j)^.data,20,4),year2,err);
- //val(copy(mas[i],20,4),year1,err);
- //val(copy(mas[j],20,4),year2,err);
- if(year1 < year2) then
- begin
- buf := getElemById(head,i)^.data;
- getElemById(head,i)^.data:= getElemById(head,j)^.data;
- getElemById(head,j)^.data := buf
- //buf := mas[i];
- //mas[i]:= mas[j];
- //mas[j] := buf;
- end;
- end;
- end;
- end;
- begin
- assign(input,'input.txt');
- reset(input);
- assign(output,'output_.txt');
- rewrite(output);
- head := nil;
- tail := nil;
- for i:=1 to 10 do
- begin
- readln(input,info);
- writeln(output,info);
- add(head,tail,info);
- end;
- close(input);
- close(output);
- print(head);
- writeln(getElemById(head,2)^.data);
- sortirovka(head,tail);
- writeln;
- print(head);
- (*
- append(output);
- writeln(output);
- for i:=1 to 3 do
- begin
- writeln(output,mas[i]);
- end;
- close(output);
- writeln;
- for i:=1 to 3 do
- begin
- writeln(mas[i]);
- end;
- *)
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement