Вопрос задан 09.11.2018 в 23:10. Предмет Информатика. Спрашивает DELETED.

Строка является палиндромом, если слева направо и справа налево она читается одинаково, например

"кабак", "боб", "asdfggf' dsa". Составьте алгоритм и напишите программу, определяющую, является ли строка палиндромом.
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Мачулина Даша.


Function Palindrome (const s: string): boolean;

var i, len: integer;
begin
    i:= 0;
    len:= length (s);
    result:= true;
    while (i < len div 2) and result do
         begin
             inc (i);
             result:= s[i] = s[len + 1 - i]
         end 

end;

Решение на паскале
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

To determine if a string is a palindrome, you can follow these steps:

1. Remove any non-alphanumeric characters from the string. 2. Convert the string to lowercase to ignore case sensitivity. 3. Compare the string with its reverse. If they are the same, then the string is a palindrome.

Here's an algorithm to check if a string is a palindrome:

1. Initialize a variable `cleanString` as an empty string. 2. Iterate through each character in the input string: - If the character is alphanumeric, append it to `cleanString`. 3. Convert `cleanString` to lowercase. 4. Initialize a variable `reverseString` as an empty string. 5. Iterate through each character in `cleanString` in reverse order: - Append each character to `reverseString`. 6. Compare `cleanString` with `reverseString`: - If they are the same, then the input string is a palindrome. - Otherwise, it is not a palindrome.

Here's a Python program that implements the above algorithm:

```python def is_palindrome(string): clean_string = ''.join(char.lower() for char in string if char.isalnum()) reverse_string = clean_string[::-1] return clean_string == reverse_string

# Example usage input_string = "asdfggf'+dsa" if is_palindrome(input_string): print(f"{input_string} is a palindrome.") else: print(f"{input_string} is not a palindrome.") ```

This program will output: `"asdfggf'+dsa is a palindrome."`

Please note that the program removes non-alphanumeric characters before checking for palindromes. If you want to consider non-alphanumeric characters as well, you can remove the line `clean_string = ''.join(char.lower() for char in string if char.isalnum())`.

0 0

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос