Advertisement
eggggggggor

oridnal number of a word with unique adjacent letters

Apr 27th, 2024
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.40 KB | None | 0 0
  1. program uniqueWords;
  2.  
  3. uses
  4.   SysUtils;
  5.  
  6. function areAllLettersUnique(word: string): boolean;
  7. var
  8.     i: integer;
  9. begin
  10.     for i := 1 to length(word) - 1 do
  11.     begin
  12.         if word[i] = word[i + 1] then
  13.         begin
  14.             areAllLettersUnique := false;
  15.             exit;
  16.         end;
  17.     end;
  18.     areAllLettersUnique := true;
  19. end;
  20.  
  21. var
  22.     text: string;
  23.     word: string;
  24.     i, wordCount: integer;
  25.     found: boolean;
  26. begin
  27.     Write('Введите текст: ');
  28.     ReadLn(text);
  29.  
  30.     found := false;
  31.     wordCount := 0;
  32.     i := 1;
  33.  
  34.     // Iterate through each character in the text
  35.     while i <= length(text) do
  36.     begin
  37.         // Extract a word from the text
  38.         word := '';
  39.         while (i <= length(text)) and (text[i] <> ' ')  do
  40.         begin
  41.             word := word + text[i];
  42.             i := i + 1;
  43.         end;
  44.         wordCount := wordCount + 1;
  45.         WriteLn('..', word, ' ', i,'..');
  46.         // Check if the word has all unique adjacent letters
  47.         if areAllLettersUnique(word) then
  48.         begin
  49.             Write(wordCount, ' ');
  50.             found := true;
  51.         end;
  52.  
  53.         i := i + 1;
  54.     end;
  55.     WriteLn;
  56.     // If no words with the required condition are found, output a message
  57.     if not found then
  58.         WriteLn('В тексте нет слов, где все соседние буквы различны.');
  59. end.
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement