zoukankan      html  css  js  c++  java
  • C++通配符

    #include<iostream>
    using namespace std;
    bool PathernMatch(char *pat, char *str)
    {
    char *s = NULL;
    char *p = NULL;
    bool star = false;
    bool bBreak = false;
    do
    {
    bBreak = false;
    for (s = str, p = pat; *s; ++s, ++p)
    {
    switch (*p)
    {
    case '?':
    break;
    case '*':
    star = true; //出现*匹配符
    str = s;
    pat = p;
    if (!*++pat)
    return true;
    bBreak = true; //退出循环
    break;
    default:
    if (*s != *p)
    {
    if (!star)
    return false;
    str++;
    bBreak = true;
    }
    break;
    }
    if (bBreak) //退出循环 重新开始循环
    break;
    }
    if (bBreak == false)
    {
    if (*p == '*')
    ++p;
    return (!*p);
    }
    } while (true);
    }
    int main()
    {
    char a[100] = "\Device\*\Content.IE5\index.dat";
    char c[100] = "\Device\*\Content.IE5\*\index.dat";
    char b[100] = "\Device\Harddiskvolume\Content.IE5\Femporary Internet Files\Content.IE5\index.dat";
    char d[100] = "\*\Content.IE5\index.dat";
    char e[100] = "*层图层*顶";
    char f[100] = "一层图层";
    char g[100] = "二层图层";
    char h[100] = "二三层图层";
    char i[100] = "二搜索三层图层顶顶顶";

    cout << PathernMatch(e, f) << endl;
    cout << PathernMatch(e, g) << endl;
    cout << PathernMatch(e, h) << endl;
    cout << PathernMatch(e, i) << endl;
    return 0;
    }

  • 相关阅读:
    就业指导【黄春霞】
    百度面试题
    面试题08-多线程网络
    面试题07-内存管理
    面试题06-Foundation
    面试题05-UI控件
    面试题04-应用程序
    面试题03-第三方框架
    面试题02-客户端安全性和框架设计
    面试题01-数据存储
  • 原文地址:https://www.cnblogs.com/Pond-ZZC/p/11881709.html
Copyright © 2011-2022 走看看