int match(char *s1, char *s2) { if (!*s1 && !*s2) //ΠΎΠ±Π΅ ΡΡΡΠΎΠΊΠΈ ΠΊΠΎΠ½ΡΠΈΠ»ΠΈΡΡ return 1; if (*s1 && *s2 == '*') return match(s1 + 1, s2) || //Π»Π΅Π²ΡΠΉ Π½Π° * match(s1, s2 + 1); // ΠΊΠΎΠ½Π΅Ρ * if (*s2 == '*') return match(s1, s2 + 1); // ΠΊΠΎΠ½Π΅Ρ * if (*s1 == *s2) // ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²ΡΠ΅ ΡΠΈΠΌΠ²ΠΎΠ»Ρ return match(s1 + 1, s2 + 1); //ΠΎΠ±Π° ΠΏΡΠΎΠΏΡΡΠΊΠ°Π΅ΠΌ return 0; //Π½Π΅ ΡΠΎΠ²ΠΏΠ°Π»ΠΎ } int nmatch(char *s1, char *s2) { if (!*s1 && !*s2) //ΠΎΠ±Π΅ ΡΡΡΠΎΠΊΠΈ ΠΊΠΎΠ½ΡΠΈΠ»ΠΈΡΡ return 1; if (*s1 == '*' && *s2 == '*') return nmatch(s1 + 1, s2); //Π·Π²ΡΠ·Π΄ΠΎΡΠΊΠ° Π½Π° Π»Π΅Π²ΡΡ ΡΡΡΠΎΠΊΡ? ΠΎΡΠΈΠ±ΠΊΠ°? if (*s1 == *s2) return nmatch(s1 + 1, s2 + 1); // ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²ΡΠ΅ ΡΠΈΠΌΠ²ΠΎΠ»Ρ if (*s2 == '*' && !*s1) return nmatch(s1, s2 + 1); // ΠΊΠΎΠ½Π΅Ρ * if (*s2 == '*') return nmatch(s1 + 1, s2) //Π»Π΅Π²ΡΠΉ Π½Π° * + // ΡΡΠΈΡΠ°Π΅ΠΌ ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ Π²Π°ΡΠΈΠ°Π½ΡΠΎΠ²? nmatch(s1, s2 + 1); // ΠΊΠΎΠ½Π΅Ρ * return 0; }
This is the simplest regular check algorithm, in which the pattern contains only symbols and * . In version 2, it is taken into account that 1 line may contain *. But if you count the number of ways, you should do it by analogy with the option with the sum.
IMPORTANT algorithm is extremely slow. Test:
aaaaaaaaaaaaaaaaaaa ******************b
*s1 *s2will be equal to'\0'- Andrew Romanenko