80.1k views
4 votes
Read a string from the standard input (the string does not contain any spaces or tabs).

If the entire string consists of consecutive characters and all are small letters display:
Consecutive and all small letters
followed by a new line, if all capital letters, replace small by capital. If the letters are not consecutive,
display Not consecutive.
In both cases end the display by a new line

User Yellowfog
by
8.1k points

1 Answer

3 votes

Final answer:

The task is to write a program that reads a string and checks if the characters are consecutive and in the same case, either all lowercase or uppercase, and then display the appropriate message. The solution involves iterating through the string and comparing each character with the previous one.

Step-by-step explanation:

The question pertains to a programming task which involves reading a string of characters from the standard input without spaces or tabs. To provide a solution, we would write a program that checks if the characters in the string are consecutive and have the same case (either all lowercase or all uppercase).

First, we need to define what we consider consecutive characters. Characters are consecutive if each character is one position higher than its predecessor in the Unicode (or ASCII) table. For example, 'abc' or 'XYZ' are strings with consecutive characters, but 'abd' or 'XYY' are not.

If the string contains all small (lowercase) letters and they are consecutive, we display: "Consecutive and all small letters". Conversely, if all the letters are capital (uppercase) and consecutive, we replace the word 'small' with 'capital' in the message. If the characters in the string are not consecutive, regardless of their case, we display: "Not consecutive".

Let's go through a simple algorithm to solve this:

  1. Read the input string.
  2. Check if the first character is lowercase or uppercase and store this information.
  3. Iterate through the string to check if each character is consecutive with the previous one.
  4. If characters are consecutive and all lowercase or all uppercase, display the corresponding message.
  5. If at any point characters are not consecutive, display "Not consecutive" and exit.

User DennisW
by
8.0k points