Still not fully studied, and require a lab! Help, brother decided I do not know whether it is right.

Given a positive integer n, the symbols s1, .., sn. Obtain a sequence of characters containing only the last occurrences of each character while preserving the mutual order of these occurrences.

uses crt; const nmax=100; type u=^real; var x:array[1..nmax] of u; n,i:byte; p,s:u; begin clrscr; randomize; repeat write('Размер массива от 3 до ',nmax,' n='); readln(n); until n in [3..nmax]; writeln('Массив:'); for i:=1 to n do begin new(x[i]); x[i]^:=5*random; write(x[i]^:0:2,' '); end; writeln; writeln; new(p); p^:=x[n-1]^+x[n]^+2*x[1]^; for i:=1 to n-2 do p^:=p^*(x[i]^+x[i+1]^+2*x[n-i+1]^); write('Произведение=',p^:0:2); for i:=1 to n do dispose(x[i]); dispose(p); readln end. 
  • What for such simple problems dynamic structures melon? - Artem

1 answer 1

Create an array, where the characters will be indices. Mark them as -1. When we read a character in the array [ch] = idx; where array is our array, ch is the read character and idx is the index by which it went in the account. After that, as everyone thought, we do n iterations in each of which we go through our array and see if there is anything to put on the i-th index or not. If there is, then output

Approximately such an implementation. Because I wrote directly on the fly in the comments, possible errors. Only small letters of the English alphabet are counted here. In order to take into account all the characters you need to write a: array [char] of integer; and the cycle where j occurs is redone on j: = # 0 to # 255

 var a : array ['a'..'z'] of integer; n, i: integer; j, ch: char; begin readln(n); for j := 'a' to 'z' do a[j] := -1; for i := 1 to n do begin read(ch); a[ch] := i end; for i := 1 to n do begin for j := 'a' to 'z' do if a[j] = i then begin write(j); break end end end