zoukankan      html  css  js  c++  java
  • 2015-09-09 [一点资讯]--数据抓取和处理工程师--3面

    时间:2015-09-09 13:40 ~ 14:40

    地点:北京市海淀区王庄路1号 清华同方科技广场D座 西区 7层

    1. A 和 B 有多少bit不一样

    #include <climits>
    #include <cmath>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    // Return the number of difference bits of a and b
    // Return 1 if a = 0 and b = 1
    // Return 2 if a = 0 and b = 3
    int diff(int a, int b)
    {
        int ans = 0;
    
        a = a ^ b;
    
        int i = 32;
        int j = 1;
    
        while (i--) {
    
            if (a & j)
                ans++;
    
            j <<= 1;
        }
    
        return ans;
    }
    
    int main()
    {
        const struct TestCase {
            int a;
            int b;
            int ret;
        } test_cases[] = {
            { 0, 1, 1 },
            { 0, 2, 1 },
            { 0, 3, 2 },
            { 1, 3, 1 },
            { -1, 0, 32 },
            { -1, 3, 30 },
            { -1, 0x7FFFFFFF, 1 },
        };
    
        for (int iii = 0; iii < sizeof(test_cases) / sizeof(TestCase); iii++) {
            const TestCase &tc = test_cases[iii];
    
            const int actual_ret = diff(tc.a, tc.b);
    
            if (tc.ret != actual_ret) {
                cout << "Case #" << iii << ": FAILED" <<  endl;
                cout << "	Expected ret=" << tc.ret << endl;
                cout << "	Acutal   ret=" << actual_ret << endl;
            }
        }
    
        return 0;
    }

    2. grep 查找第一行

    grep "what_you_want" target_file | head -n 1

    3. 在100GB的文件中查找某一天的第一条日志

    二分查找的实际应用,需要注意健壮性。

  • 相关阅读:
    Linux系统
    Maven常用命令有哪些?
    .Maven的工程类型有哪些?
    什么是Maven?
    Shiro 的优点
    比较 SpringSecurity 和 Shiro
    Maven的工程类型有哪些?
    Maven仓库是什么
    什么是Maven?
    什么是 JavaConfig?
  • 原文地址:https://www.cnblogs.com/lovers/p/4803566.html
Copyright © 2011-2022 走看看