Time: 2015-09-09 13:40 ~ 14:40
Location: No. 1th, Wang Zhuang Road, Haidian District , Beijing Tongfang Science and Technology Plaza, Block D, West 7
1. How many bits a and B are different
#include <climits>#include<cmath>#include<cstdlib>#include<cstring>#include<iostream>#include<iomanip>#include<string>using namespacestd;//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 = 3intDiffintAintb) { intAns =0; A= a ^b; inti = +; intj =1; while(i--) { if(A &j) Ans++; J<<=1; } returnans;}intMain () {Const structTestCase {intA; intb; intret; } test_cases[]= { { 0,1,1 }, { 0,2,1 }, { 0,3,2 }, { 1,3,1 }, { -1,0, + }, { -1,3, - }, { -1,0x7FFFFFFF,1 }, }; for(intIII =0; III <sizeof(test_cases)/sizeof(TestCase); iii++) { ConstTestCase &TC =TEST_CASES[III]; Const intActual_ret =diff (TC.A, tc.b); if(Tc.ret! =Actual_ret) {cout<<"Case #"<< III <<": FAILED"<<Endl; cout<<"\texpected ret="<< Tc.ret <<Endl; cout<<"\tacutal ret="<< Actual_ret <<Endl; } } return 0;}
2. grep finds the first line
grep "What_you_want" Target_file | Head-n 1
3. Find the first log of a day in a 100GB file
The practical application of binary search requires attention to robustness.
2015-09-09 [Little information]--data capture and processing engineer--3 face