题目描述:
How would you print just the 10th line of a file?
For example, assume that file.txt has the following content:
Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 ...
How would you print just the 10th line of a file?
For example, assume that file.txt has the following content:
Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 ...
Given a text file file.txt, transpose its content.
You may assume that each row has the same number of columns and each field is separated by the ' ' character.
For example, if file.txt has the following ...
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bash script to print all valid phone numbers.
You may assume that a valid phone number must appear in one ...
Write a bash script to calculate the frequency of each word in a text file words.txt.
For simplicity sake, you may assume:
Reverse bits of an unsigned integer.
将无符号整数按位反转
有几种方法可以实现一个无符号整数的按位反转。在此,我们设计一个使用异或交换(XOR swap)技巧的算法,然后使用分治法对其进行优化。
怎样实现第i位与第j位的对调?想想能否使用异或操作实现。
按位反转可以通过将低n/2位与高位对换实现。技巧就是实现一个名为swapBits(i, j)的函数,将第i位与第j位对换。回忆一下异或运算的原理:0 ^ 0 == 0, 1 ^ 1 == 0, 0 ^ 1 == 1, and 1 ^ 0 == 1。
我们只需要在第i位与第j位不同时执行对换 ...