İki s1 və s2 sətri verilmişdir, burada s1 vəhşi kart simvollarını ehtiva edir və s2 normal sətirdir. Verilən sətirlərin hər ikisi uyğun gəlsə, geriyə dönəcək bir funksiya yazın
Aşağıdakı joker simvollara icazə verilir
'*' = Hər hansı bir simvol və ya simvol dəstinin sıfır və ya daha çox nümunəsi ilə uyğunlaşma
Misal:
"Pro * ing" ilə "Proqramlaşdırma" uyğunlaşdırılacaq
'?' = Hər hansı bir simvolla uyğunlaşdı
Misal:
“Pro? İng” “Proking” ilə uyğunlaşdırılacaq
misal
GİRİŞ:
s1 = “Pro? gr *”
s2 = “Proqramlaşdırma”
Çıxış:
TRUE
Alqoritm
1. Əgər s1-dən sonra simvollar varsa və s2-də '*' dən sonra heç bir simvol yoxdursa, yalan işarəsini qaytarın
2. S1 sətirində '?' Varsa və ya hər iki simlin cari simvolları uyğun gəlir, sonra s1 və s2-nin qalan hissəsinə rekursiv bir zəng edin, yəni s1 + 1, s2 + 1
3. '*' Varsa, iki ehtimal var
a. s2, yəni charMatching (s1 + 1, s2) cari xarakterini nəzərdən keçiririk
b. s2, yəni charMatching (s1, s2 + 1) cari xarakterini nəzərə almırıq
C ++ Proqramı
#include <bits/stdc++.h> using namespace std; bool charMatching(char *s1, char * s2) { // If we reach at the end of both strings, we are done if (*s1 == '\0' && *s2 == '\0') return true; // Make sure that the characters after '*' are present // in s2 string. if (*s1 == '*' && *(s1+1) != '\0' && *s2 == '\0') return false; // If the s1 string contains '?', or current characters // of both strings match if (*s1 == '?' || *s1 == *s2) return charMatching(s1+1, s2+1); // If there is *, then there are two possibilities // We consider current character of s2 string or We ignore current character of s2 string. if (*s1 == '*') return charMatching(s1+1, s2) || charMatching(s1, s2+1); return false; } int main() { char s1[] = "Prog*ing"; char s2[] = "Programming"; if(charMatching(s1, s2)) { cout<<"TRUE"<<endl; } else { cout<<"FALSE"<<endl; } return 0; }
Yoxla