ARTS] punch eighth week

ARTS completed a week

  • Do at least a week leetcode algorithm problem

  • Read and review at least one technical articles in English

  • At least one technical skill learning

  • Share ideas and think there is a technical article.

  • (That is, Algorithm, Review, Tip, Share short ARTS)

    Algorithm

    290. word law

    Given a law and a pattern string str, str determines whether to follow the same rule.

    Here follow the exact match means, for example, there is a corresponding pattern regularity in two-way connection between each letter string str and each non-empty word.

    Ideas:

    Two map, the correspondence of each string of letters, a string of letters and

    class Solution {
    public:
    
        vector<string> getvec(string str)
        {
            vector<string> vec;
    
            if (str.empty())
                return vec;
    
            char *szstr = new char[str.size() + 1];
            strcpy(szstr, str.c_str());
    
            char *p = strtok(szstr, " ");
            while(p)
            {
                vec.push_back(p);
                p = strtok(NULL, " ");
            }
            delete szstr;
    
            return vec;
        }
    
        bool wordPattern(string pattern, string str) {
            unordered_map<char, string> map1;
            unordered_map<string, char> map2;
    
            vector<string> vstr = getvec(str);
    
            if (pattern.size() != vstr.size())
                return false;
    
            bool issame = true;
    
            int i = 0;
            for (auto e: pattern)
            {
                if (map1.find(e) == map1.end())
                {
                    map1.insert(pair<char, string>(e, vstr[i]));
                }
                else
                {
                    if (map1[e] != vstr[i])
                    {
                        issame = false;
                        break;
                    }
                }
    
                if (map2.find(vstr[i]) == map2.end())
                {
                    map2.insert(pair<string, char>(vstr[i], e));
                }
                else
                {
                    if (map2[vstr[i]] != e)
                    {
                        issame = false;
                        break;
                    }
                }
                i ++;
            }
    
            return issame;
        }
    };

    Review

    une Your Hard Disk with hdparm

    Hdparm introduced this software under linux is an important diagnostic, adjustment tool hard disk drive.

    Basic information showing hard drive:

    hdparm -I /dev/sda

    Speed ​​Test:

    hdparm -t /dev/sda

    Tip

    Linux sed command to insert a new row before and after the match line

    a matching row is added in the back row
    b add an additional row in front of the matching line

    Share

    C ++ generation and a strategy to avoid memory leaks and memory fragmentation

Guess you like

Origin www.cnblogs.com/JesseTsou/p/11516454.html