Is- dp求正则表达式

#include <iostream>

using namespace std;


int main()

{

    char a[101],b[101];

    int n;

    scanf("%s",a);

    scanf("%d",&n);

    while (n--) {

        scanf("%s",b);

        int i,j,k,l1=strlen(a),l2=strlen(b);

        bool d[101][101];

        for (i=l1; i>=0; i--)

            for (j=l2; j>=0; j--) {

                if (i==l1&&j==l2)

                    d[i][j]=1;

                else if (a[i]==b[j])

                    d[i][j]=d[i+1][j+1];

                else if (a[i]=='*') {

                    d[i][j]=0;

                    for (k=j; k<=l2; k++)

                        if (d[i+1][k]) {

                            d[i][j]=1;

                            break;

                        }

                }

                else d[i][j]=0;

            }

        if (d[0][0])

            printf("%s\n",b);

    }

    return 0;

}


/*

 Problem description

 You are implementing an operating system, and now need to write a program to list files in a directory: `ls'. You want the user to be able to list only files that match a given pattern that can include wildcards (*), for example *.c. A wildcard matches zero or more characters of any kind.

 

 

 Input

 The first line contains a string P, containing 1-100 characters 'a'-'z', '*' and '.'. This is the pattern. The second line contains an integer N, 1 <= N <= 100, which is the number of files in the directory. Then follows N lines containing the names of the files in the directory. Each line is a string containing 1{100 characters 'a'-'z' and '.'.

 

 Output

 The output shall consist of the lenames that match the pattern, P, each on its own line, in the same order that they were given as input.

 

 Sample Input

 *.*

 4

 main.c

 a.out

 readme

 yacc

 *a*a*a

 4

 aaa

 aaaaa

 aaaaax

 abababa

 Sample Output

 main.c

 a.out

 aaa

 aaaaa

 abababa

*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值