برنامه نویسی

تأیید حضور در الگوی با استفاده از رشته ها

مقدمه
ایجاد برنامه ای برای برنامه ای که جستجو کند آیا رشته کوچکتر در رشته دیگری وجود دارد.
فرض بر این است که طول رشته کوچکتر کمتر از طول رشته بزرگتر خواهد بود

الگوریتم

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
حالت تمام صفحه را وارد کنید

از حالت تمام صفحه خارج شوید

نمودار جریان
شرح تصویر

شبه

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
حالت تمام صفحه را وارد کنید

از حالت تمام صفحه خارج شوید

پایان
کد پیشنهادی با استفاده از حلقه ها هنگام شناسایی الگوی و کاهش می یابد.
افزونگی وقتی که الگوی ناسازگار می شود از بین می رود.

نوشته های مشابه

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

دکمه بازگشت به بالا