In a text file, count the number of lines that begin and end with the same consonant letter. Please help with this program.
2 answers
Delphi:
var i,n:integer;s:string; begin n:=0; Memo1.lines.LoadFromFile('1.txt'); for i:=0 to Memo1.Lines.Count-1 do begin s:=Memo1.Lines[i]; if (s[1]='Согласная') and (s[Length(s)]='Согласная') then inc(n); end; end;
- What is it like? - Altair
- Is it completely? - Altair
|
The algorithm is simple here:
- Read the next line;
- Translate it into one register - for example, in the upper one;
- See the first letter - if it does not agree (for this there must be a list of consonant letters, with which you must compare it one by one), then go to the beginning, to point 1;
- The last letter is searched and compared with the first. If it is the same, add one to the counter.
|