• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

Pattern presence verification using strings

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
1 Мар 2015
Сообщения
1,481
Баллы
155
Intro
Creating a plan for a program that searches whether a smaller string exists in another string.
It is assumed that the length of the smaller string would be less than the length of the larger string

Algorithm


Input Get the text string
Input Get the Pattern string
Process: Create patternExists variable and set to fault
Condition 1: Have we reached the end of the text string
Process: get the first/next character of text string and store it in a variable called "char0"
Condition: have we reached the end of the pattern text
Process: Get the char0+"index of pattern string" of text string and store it in variable "char1"
Process: get the first/next character of pattern string and store it in variable "char2"
Condition:Is char1 and char2 the same:
Condition: Have we reached the end of the pattern string:
Process: set patternExists varible to true
Break
Condition Else:
Break

Condition Else:
Process: set patternExists variable to false
Break


Print the status of patternExists

Flow Chart

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



Pseudocode


text= get input
pattern =get input
patternExists= False
While end of text no reached (index using i)
char0= character at current index number
While end of pattern text is not reached (index using j)
char1=text[i+j]
char2=pattern[j]
if char1==char2
patternExists=True
else
patternExists=False
break
if patternExists==True
break
if patternExists==true
print pattern exists in text
else
print pattern does not exist in text

Conclusion
The code suggested works efficiently as it breaks away from loops when the pattern is identified and reduces
redundancy as it breaks away when the pattern mismatches.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу