精华内容
下载资源
问答
  • findStr

    2018-12-02 23:08:00
    目录 规则 目录结构 src/main.cpp src/findstr.cpp include/findstr.h ft/TestCase.cpp ft/makefile ftbuild.sh mainbuild.sh...

    规则

    在一个由大小写字母组成的矩阵中查找一个给定的字符串,这个字符串要求在矩阵中串成一个拐直角弯的相连序列,
    形状像贪吃蛇一样,如果矩阵中存在这样的序列则查找成功。

    目录结构

    1494427-20181202231156132-1806566872.png

    src/main.cpp

    #include "../include/findstr.h"
    int main(int argc, char* argv[])
    {
        if(argc !=3)
        {
            cout<<"argc should is 3, now it is "<<argc<<endl;
            return 1;
        }
        findStr(argv[1],argv[2]);
        return 0;
    }

    src/findstr.cpp

    #include "../include/findstr.h"
    
    using namespace std;
    StrMatrix::StrMatrix(vector<string>&vectstr)   
    {
        row = vectstr.size();
        if(row>0)
        {
            col = vectstr[0].length();
        }
        else 
            return;
        size = row*col;
        pchar = new char[size];
        pflag= new int[size];
        int trow=0;
        for (string str :vectstr)
        {
            for(int j=0; j<col ; j++)
            pchar[j+trow*col] = str[j];
            trow++;
        }
    }
    void StrMatrix::clearFlag()
    {
        for (unsigned j = 0; j<size; j++) 
        {
            pflag[j] = 1;
        }
    }
    void StrMatrix::print()
    {
        for (unsigned j = 0; j<size; j++) 
        {
            cout<<pchar[j]<<" ";
            if((j+1)%col==0)
                cout<<endl;
        }
    }
    
    char StrMatrix::getchar(unsigned i, unsigned j)
    {
        if(i<row && j<col)
            return pchar[i*col+j];
        else
            return ' ';
    }
    StrMatrix::~StrMatrix()
    {
        if (pchar != NULL)
        {
            delete[]pchar;
            pchar= NULL;
        }
        if (pflag!= NULL)
        {
            delete[]pflag;
            pflag= NULL;
        }
    }
    void StrMatrix::setUsed(unsigned i,unsigned j)
    {
        if(i<row && j<col)
            pflag[i*col+j]=0;
    }
    int StrMatrix::notUsed(unsigned i,unsigned j)
    {
        if(i<row && j<col)
            return  pflag[i*col+j] ;
        else
            return 0;
    }
    vector<string> split(const string &str, string ch = " ")
    {
        vector<string>ret;
        int pos = 0;
        int start = 0;
        while ((pos = str.find(ch, start) )!= string::npos )
        {
            //cout << "pos:" << pos << endl;
            if (pos>start)
            ret.push_back(str.substr(start, pos-start));
            start = pos+ch.size();
        }
        if (str.size()>start)
        ret.push_back(str.substr(start));
        return ret;
    }
    
    int checkPos(int i,int j, int*pos, char ch, int &validnum, StrMatrix &charMat)
    {
        if(charMat.notUsed(i,j) && charMat.getchar(i,j) == ch)
        {
            pos[validnum] = i;
            pos[validnum+1] = j;
            validnum+=2;
        }
    }
    
    int recursion(int i,int j,StrMatrix  &charMat, string curstr)
    {
        int ret=1;
        int pos[6];
        int validnum=0;
        checkPos(i,j+1,pos,curstr[0],validnum,charMat);
        checkPos(i,j-1,pos,curstr[0],validnum,charMat);
        checkPos(i-1,j,pos,curstr[0],validnum,charMat);
        checkPos(i+1,j,pos,curstr[0],validnum,charMat);
    
        if(validnum>0 && curstr.length()==1)
        {
            //cout<<"has find!"<<endl<<endl;
            return 0;
        }
        for(int cnt=0; cnt<validnum; cnt+=2)
        {
            //cout<<"ch: "<<charMat.getchar(pos[cnt],pos[cnt+1])<<endl;
            charMat.setUsed(pos[cnt],pos[cnt+1]);
            ret = recursion(pos[cnt],pos[cnt+1], charMat, curstr.substr(1));
            if(ret == 0)
                return 0;
        }
        return ret;
    }
    int findSingleStr(StrMatrix &charMat, string& curstr)
    {
        int ret=1;
        for(int i=0; i<charMat.row; i++)
        {
            for(int j=0; j<charMat.col ; j++)
            {
                if(charMat.getchar(i,j) == curstr[0] )
                {
                    if(curstr.length()==1)
                        return 0;
                    cout<<"head char:"<<charMat.getchar(i,j)<<endl;
                    charMat.clearFlag();
                    charMat.setUsed(i,j);
                    ret = recursion(i,j,charMat,curstr.substr(1));  
                    if (ret == 0)
                    {
                        cout<<"find str:"<<curstr<<endl;
                        return 0;
                    }
                }
            }
        }
        return ret;
    }
    int findStr(string argvone,string argvtwo)
    {
        vector<string>onemat=split(argvone);
        StrMatrix charMat(onemat);
        charMat.print();
    
        vector<string>strMatrix=split(argvtwo);
    
        int ret=0;
        for (string curstr :strMatrix)
        {
            //cout<<"curstr:"<<curstr<<endl;
            ret |= findSingleStr(charMat, curstr );   
        }
        return ret;
    
    }

    include/findstr.h

    #include<iostream>  
    #include<string>  
    #include<vector>  
    using namespace std;
    
    class StrMatrix{
    public:
        unsigned  row, col, size;   
        char*pchar;
        int*pflag;
        StrMatrix(vector<string>&vectstr);
        ~StrMatrix();
        void setUsed(unsigned i,unsigned j);
        int notUsed(unsigned i,unsigned j);
        void clearFlag();
        void assignCharArr(vector<string>&);
        char getchar(unsigned i, unsigned j);
        void print();
    };
    
    vector<string> split(const string &str, string ch );
    
    int findSingleStr(StrMatrix &charMat, string& curstr);
    
    int findStr(string argvone,string argvtwo);
    

    ft/TestCase.cpp

    
    
    #include <gtest/gtest.h>
    #include "../include/findstr.h"
    TEST(FooTest, SingleCharCase)
    {
        EXPECT_EQ(findStr("qwer asdf zxcv", "s a d"),0);
    }
    TEST(FooTest, multiStrCase)
    {
        EXPECT_EQ(findStr("qwer asdf zxcv", "qwsxcv qwedsazxcv rfvcxzaswq"),0);
    }
    TEST(FooTest, UseTwiceiSameChar)
    {
        EXPECT_EQ(findStr("qwer asdf zxcv", "aa cvc qazxz"),1);
    }
    
    TEST(FooTest, NotSerieschar)
    {
        EXPECT_EQ(findStr("qwer asdf zxcv", "qsc asf zxdf qwdf"),1);
    }

    ft/makefile

    cc = g++ -std=c++11 
    prom = ../output/ft
    deps = ../include/findstr.h 
    obj = ../src/findstr.o  TestCase.o
    LIBS = -lgtest -lgtest_main -lpthread
    
    $(prom): $(obj)
        $(cc) $(obj)  $(LIBS) -o $(prom)
    
    %.o: %.c $(deps)
        $(cc) -c $< -o $@

    ftbuild.sh

    cd ft
    make
    cd ../output
    echo $(pwd)
    ./ft

    mainbuild.sh

    g++ -std=c++11 -g src/*.cpp -o output/findstr
    

    转载于:https://www.cnblogs.com/ims-/p/10056138.html

    展开全文
  • Findstr

    2016-12-16 15:42:28
    Findstr Searches for patterns of text in files using regular expressions. Syntax findstr [/b] [/e] [/l] [/r] [/s] [/i] [/x] [/v] [/n] [/m] [/o] [/p] [/offline] [/g:file] [/f:file] [/c:...

    Findstr

    Searches for patterns of text in files using regular expressions.

    Syntax

    findstr [/b] [/e] [/l] [/r] [/s] [/i] [/x] [/v] [/n] [/m] [/o] [/p] [/offline] [/g:file] [/f:file] [/c:string] [/d:dirlist] [/a:ColorAttribute] [strings] [[Drive:][Path] FileName [...]]

    Parameters

    /b   : Matches the pattern if at the beginning of a line.

    /e   : Matches the pattern if at the end of a line.

    /l   : Uses search strings literally.

    /r   : Uses search strings as regular expressions. Findstr interprets all metacharacters as regular expressions unless you use /l.

    /s   : Searches for matching files in the current directory and all subdirectories.

    /i   : Specifies that the search is not to be case-sensitive.

    /x   : Prints lines that match exactly.

    /v   : Prints only lines that do not contain a match.

    /n   : Prints the line number before each line that matches.

    /m   : Prints only the file name if a file contains a match.

    /o   : Prints seek offset before each matching line.

    /p   : Skips files with non-printable characters.

    /offline   : Processes files with offline attribute set.

    /f: file   : Reads file list from the specified file.

    /c: string   : Uses specified text as a literal search string.

    /g: file   : Gets search strings from the specified file.

    /d: dirlist   : Searches a comma-delimited list of directories.

    /a: ColorAttribute   : Specifies color attributes with two hexadecimal digits.

    strings   : Specified text to be searched for in FileName.

    [ Drive : ][ Path ] FileName [...] : Specifies a file or files to search.

    /?   : Displays help at the command prompt.

    Remarks

    • Using regular expressions with findstr 

      Findstr is capable of finding the exact text you are looking for in any ASCII file or files. However, sometimes you have only part of the information that you want to match, or you want to find a wider range of information. In such cases, findstr has the powerful capability to search for patterns of text using regular expressions.

      Regular expressions are a notation for specifying patterns of text, as opposed to exact strings of characters. The notation uses literal characters and metacharacters. Every character that does not have special meaning in the regular expression syntax is a literal character and matches an occurrence of that character. For example, letters and numbers are literal characters. A metacharacter is a symbol with special meaning (an operator or delimiter) in the regular-expression syntax.

      The following table lists the metacharacters that findstr accepts.

      Character

      Value

      .

      Wildcard: any character

      *

      Repeat: zero or more occurrences of previous character or class

      ^

      Line position: beginning of line

      $

      Line position: end of line

      [class]

      Character class: any one character in set

      [^class]

      Inverse class: any one character not in set

      [x-y]

      Range: any characters within the specified range

      \x

      Escape: literal use of metacharacter x

      \<xyz

      Word position: beginning of word

      xyz\>

      Word position: end of word

      The special characters in regular expression syntax are most powerful when you use them together. For example, the following combination of the wildcard character (.) and repeat (*) character match any string of characters:

      .*

      Use the following expression as part of a larger expression that matches any string beginning with "b" and ending with "ing":

      b.*ing

    Examples

    Use spaces to separate multiple search strings unless the argument is prefixed with /c. To search for "hello" or "there" in file x.y, type:

    findstr "hello there" x.y

    To search for "hello there" in file x.y, type:

    findstr /c:"hello there" x.y

    To find all occurrences of the word "Windows" (with an initial capital W) in the file Proposal.txt, type the following:

    findstr Windows proposal.txt

    To search every file in the current directory and all subdirectories that contained the word Windows, regardless of the letter case, type the following:

    findstr /s /i Windows *.*

    To find all occurrences of lines that contain the word "FOR", preceded by any number of spaces, (as in a computer program loop), and to include the line number where each occurrence is found, type the following:

    findstr /b /n /c:" *FOR" *.bas

    If you want to search for several different items in the same set of files, create a text file that contains each search criterion on a new line. You can also list the exact files you want to search in a text file. To use the search criteria in the file Finddata.txt, search the files listed in Filelist.txt, and then store the results in the file Results.out, type the following:

    findstr /g:finddata.txt /f:filelist.txt > results.out

    Assume you wanted to find every file in the current directory and all subdirectories that contained the word computer, regardless of the letter case. To list every file containing the word computer, type the following:

    findstr /s /i /m "\<computer\>" *.*

    Now assume you want to find not only the word "computer," but also any other words that begin with the letters comp, such as "compliment" and "compete. " type the following:

    findstr /s /i /m "\<comp.*" *.*

    Formatting legend

    Format

    Meaning

    Italic

    Information that the user must supply

    Bold

    Elements that the user must type exactly as shown

    Ellipsis (...)

    Parameter that can be repeated several times in a command line

    Between brackets ([])

    Optional items

    Between braces ({}); choices separated by pipe (|). Example: {even|odd}

    Set of choices from which the user must choose only one

    Courier font

    Code or program output

    Command-line reference A-Z

    展开全文
  • findstr

    2015-06-30 16:25:52
    findstr "hello there" aa.txt 在文件aa.txt中查找"hello there": findstr /c:"hello there" aa.txt 在Proposal.txt中查找首字母大写的“Windows”: findstr Windows proposal....
    在文件aa.txt中查找"hello"或 "there" :
    findstr "hello there" aa.txt
    在文件aa.txt中查找"hello there":
    findstr /c:"hello there" aa.txt
    在Proposal.txt中查找首字母大写的“Windows”:
    findstr Windows proposal.txt
    要在当前目录及其子目录找查找包含不区分大小写的“Windows”的文件:
    findstr /s /i Windows *.*
    要查找没有或有多个空格开头的且包含“FOR”字符的行,并显示行号:
    findstr /b /n /r /c:"^ *FOR" *.bas
    查找一系列文件中的多个字符串,可以创建一个包含字符串的文本文件,要查找到的文件放在另一个文本文件中列出。例如,包含字符串的文本文件叫Stringlist.txt,包含文件的文本文件叫Filelist.txt,并将结果输出到Results.out:
    findstr /g:stringlist.txt /f:filelist.txt > results.out
    要列出当前目录中包含忽略大小写的单词“computer”的文件:
    findstr /s /i /m "\<computer\>" *.*
    要查找包含单词 "computer"或"comp"开头的单词的文件:
    findstr /s /i /m "\<comp.*" *.*
    展开全文
  • window findstr

    2017-09-06 18:23:01
    findstr /m /i "hello" *.txt    查询 该目录下 所有txt 文件中是否包含了hello字符  

    findstr /m /i "hello" *.txt 

     

    查询 该目录下 所有txt 文件中是否包含了hello字符

     

    展开全文
  • findstr命令

    千次阅读 2015-01-12 16:15:43
    $ findstr /? 在文件中寻找字符串。 FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/F]  [/C] [/G] [/D:dir list] [/A:color attributes] [/OFF[LINE]]  strings [[drive
  • findstr正则

    千次阅读 2014-05-31 23:30:06
    findstr的正则表达式是用来定义字符串样式的 它的元字符有 .、*、[-]、\、\、^、$等。 参与运算的对象主要是字母、数字、符号、还有汉字。而且该运算具有特殊的规则。   findstr中正则表达式用法规则小结 ● ...
  • DOS命令:findstr

    2021-02-17 21:01:17
    findstr命令,在多个文件中搜索字符串 findstr/?---查看官方帮助文档对FINDSTR的解释说明 在文件中寻找字符串。 FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file] [/C:string]...
  • CMD - 查找 findstr

    2020-09-06 23:12:01
    Shell - CMD查找findstr 查找 findstr > findstr /? 在文件中寻找字符串。 FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file] [/C:string] [/G:file] [/D:dir list] [/A:color ...
  • findstr 命令使用

    2019-09-26 10:22:09
    findstr 命令使用 find /? 在文件中搜索字符串。 FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]] /V 显示所有未包含指定字符串的行。 /C 仅显示包含字符串的行数。...
  • Windows CMD findstr命令

    2020-07-10 17:24:05
    findstr命令一、作用二、命令语法三、参数解释四、例子 一、作用 findstr是Window系统自带的命令,用于查找某路径下指定的一个或多个文件中包含某些特定字符串的行,并将该行完整的信息打印出来,或者打印查询字符串...
  • find与findstr

    2015-09-17 17:38:40
    转自:... find与findstr 在文件中搜索字符串。   1.findstr . 2.txt 或 Findstr "...从文件2.txt中查找任意字符,不包括空字符或空行 ...2.findstr .* 2.txt 或 findstr...
  • find和findstr区别

    千次阅读 2019-07-17 11:12:22
    findstr和find 查找汉字时只能在936代码下使用,且查找的文件须为中文编码,utf-8格式会导致查找不到 一.区别 find 无正则 findstr 默认正则(推荐) 二.例子 test1.bat文件: chcp 65001>nul echo "你好 世界" |...
  • findstr中的空格

    2019-10-01 02:33:52
    findstr is a useful command in bat file. for instances: findstr /NI ^error.*: %DEBUG_LOG% 1>nul 2>&1 It matches error info via regular expression, if matched, build system ...
  • findstr支不支持变量查找,即将变量赋值给findstr。比如 @echo off for / findstr支不支持变量查找,即将变量赋值给findstr。比如 @echo off for /f "delims=" %%a in ('dir /ad/s/b') do ( for /f "delims=" %%b ...
  • Find 和 Findstr

    2015-09-04 11:46:00
    FINDSTR 在文件中搜索字符串。 findstr能用正则表达式,而find不能 dir c:|find /N /I /C "windows" dir c:\windows|findstr /N /I ".exe" 转载于:https://www.cnblogs.com/lbnnbs/p/4781490.html...
  • 批处理脚本应用——findstr

    千次阅读 2019-10-27 18:58:32
    批处理脚本应用——findstr
  • Powershell ——findstr

    2017-07-08 19:25:00
    从文件中找出关键字 $colItems = Get-ChildItem d:\test #定义文件夹的路径 foreach ($i in $colItems) #... $filecontent= Get-Content $i.fullName | findstr /i "a" #获取txt文件的内容 并找到数字a write...
  • 1、在使用 “adb shell dumpsys window w |findstr \/ |findstr name=” 这个指令查找APP包名时,cmd出现'findstr' 不是内部或外部命令 解决方案: 1、PATH环境变量的问题,在path中追加:(%SystemRoot%/...
  • Windows cmd findstr

    2017-02-22 14:48:00
    /********************************************************************************** * Windows cmd findstr * 说明: * 在Windows的cmd终端里要匹配字符串,Linux是gre...
  • FINDSTR 命令使用详解

    2017-12-21 13:39:00
    Findstr 使用正则表达式搜索文件中的文本模式。 语法 findstr [/b] [/e] [/l] [/r] [/s] [/i] [/x] [/v] [/n] [/m] [/o] [/p] [/offline] [/g:File] [/f:File] [/c:String] [/d:DirList] [/a:ColorAttribute] [Stri ...
  • findstr 命令使用方法

    千次阅读 2016-12-16 15:30:34
    findstr 命令使用方法 标签: 正则表达式windowspathfilestringclass 2008-02-28 09:10 14823人阅读 评论(0) 收藏 举报 分类: 计算机日常维护(32) 目录(?)[+] Findstr ...
  • FINDSTR正则表达式小结

    2019-10-18 12:35:39
    前言:最近写了一个bat用于快速编译swf至目标目录,想利用FINDSTR命令通过匹配目标目录名称,匹配数量大概600多个,发现匹配耗时比较久,大概花费10余秒,因此还是放弃字符匹配,乖乖拼出全称来定位目录。...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 10,128
精华内容 4,051
关键字:

findstr