Skip to content

Commit 34c0940

Browse files
author
lishulong
committed
init programming for every language
1 parent 51b0fac commit 34c0940

File tree

7,433 files changed

+668543
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

7,433 files changed

+668543
-0
lines changed
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<!--
2+
<p>Write a bash script to calculate the frequency of each word in a text file <code>words.txt</code>.</p>
3+
4+
<p>For simplicity sake, you may assume:</p>
5+
<ul>
6+
<li><code>words.txt</code> contains only lowercase characters and space <code>' '</code> characters.</li>
7+
<li>Each word must consist of lowercase characters only.</li>
8+
<li>Words are separated by one or more whitespace characters.</li>
9+
</ul>
10+
</p>
11+
12+
<p>For example, assume that <code>words.txt</code> has the following content:</p>
13+
<pre>the day is sunny the the
14+
the sunny is is
15+
</pre>
16+
17+
Your script should output the following, sorted by descending frequency:
18+
<pre>
19+
the 4
20+
is 3
21+
sunny 2
22+
day 1
23+
</pre>
24+
25+
<p>
26+
<b>Note:</b><br>
27+
Don't worry about handling ties, it is guaranteed that each word's frequency count is unique.
28+
</p>
29+
30+
<p class="showspoilers"><a href="#" onclick="showSpoilers(this); return false;">[show hint]</a></p>
31+
<div class="spoilers"><b>Hint:</b><br />
32+
Could you write it in one-line using <a href="http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-4.html">Unix pipes</a>?
33+
</div><p>写一个 bash 脚本以统计一个文本文件&nbsp;<code>words.txt</code>&nbsp;中每个单词出现的频率。</p>
34+
35+
<p>为了简单起见,你可以假设:</p>
36+
37+
<ul>
38+
<li><code>words.txt</code>只包括小写字母和&nbsp;<code>&#39; &#39;</code>&nbsp;。</li>
39+
<li>每个单词只由小写字母组成。</li>
40+
<li>单词间由一个或多个空格字符分隔。</li>
41+
</ul>
42+
43+
<p><strong>示例:</strong></p>
44+
45+
<p>假设 <code>words.txt</code> 内容如下:</p>
46+
47+
<pre>the day is sunny the the
48+
the sunny is is
49+
</pre>
50+
51+
<p>你的脚本应当输出(以词频降序排列):</p>
52+
53+
<pre>the 4
54+
is 3
55+
sunny 2
56+
day 1
57+
</pre>
58+
59+
<p><strong>说明:</strong></p>
60+
61+
<ul>
62+
<li>不要担心词频相同的单词的排序问题,每个单词出现的频率都是唯一的。</li>
63+
<li>你可以使用一行&nbsp;<a href="http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-4.html">Unix pipes</a>&nbsp;实现吗?</li>
64+
</ul>
65+
<p>写一个 bash 脚本以统计一个文本文件&nbsp;<code>words.txt</code>&nbsp;中每个单词出现的频率。</p>
66+
67+
<p>为了简单起见,你可以假设:</p>
68+
69+
<ul>
70+
<li><code>words.txt</code>只包括小写字母和&nbsp;<code>&#39; &#39;</code>&nbsp;。</li>
71+
<li>每个单词只由小写字母组成。</li>
72+
<li>单词间由一个或多个空格字符分隔。</li>
73+
</ul>
74+
75+
<p><strong>示例:</strong></p>
76+
77+
<p>假设 <code>words.txt</code> 内容如下:</p>
78+
79+
<pre>the day is sunny the the
80+
the sunny is is
81+
</pre>
82+
83+
<p>你的脚本应当输出(以词频降序排列):</p>
84+
85+
<pre>the 4
86+
is 3
87+
sunny 2
88+
day 1
89+
</pre>
90+
91+
<p><strong>说明:</strong></p>
92+
93+
<ul>
94+
<li>不要担心词频相同的单词的排序问题,每个单词出现的频率都是唯一的。</li>
95+
<li>你可以使用一行&nbsp;<a href="http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-4.html">Unix pipes</a>&nbsp;实现吗?</li>
96+
</ul>
97+
98+
-->
99+
100+
101+
# Read from the file words.txt and output the word frequency list to stdout.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<!--
2+
<p>Given a text file <code>file.txt</code> that contains list of phone numbers (one per line), write a one liner bash script to print all valid phone numbers.</p>
3+
4+
<p>You may assume that a valid phone number must appear in one of the following two formats: (xxx) xxx-xxxx or xxx-xxx-xxxx. (x means a digit)</p>
5+
6+
<p>You may also assume each line in the text file must not contain leading or trailing white spaces.</p>
7+
8+
<p>For example, assume that <code>file.txt</code> has the following content:</p>
9+
<pre>
10+
987-123-4567
11+
123 456 7890
12+
(123) 456-7890
13+
</pre>
14+
15+
Your script should output the following valid phone numbers:
16+
<pre>
17+
987-123-4567
18+
(123) 456-7890
19+
</pre><p>给定一个包含电话号码列表(一行一个电话号码)的文本文件 <code>file.txt</code>,写一个 bash 脚本输出所有有效的电话号码。</p>
20+
21+
<p>你可以假设一个有效的电话号码必须满足以下两种格式: (xxx) xxx-xxxx 或&nbsp;xxx-xxx-xxxx。(x 表示一个数字)</p>
22+
23+
<p>你也可以假设每行前后没有多余的空格字符。</p>
24+
25+
<p><strong>示例:</strong></p>
26+
27+
<p>假设&nbsp;<code>file.txt</code>&nbsp;内容如下:</p>
28+
29+
<pre>987-123-4567
30+
123 456 7890
31+
(123) 456-7890
32+
</pre>
33+
34+
<p>你的脚本应当输出下列有效的电话号码:</p>
35+
36+
<pre>987-123-4567
37+
(123) 456-7890
38+
</pre>
39+
<p>给定一个包含电话号码列表(一行一个电话号码)的文本文件 <code>file.txt</code>,写一个 bash 脚本输出所有有效的电话号码。</p>
40+
41+
<p>你可以假设一个有效的电话号码必须满足以下两种格式: (xxx) xxx-xxxx 或&nbsp;xxx-xxx-xxxx。(x 表示一个数字)</p>
42+
43+
<p>你也可以假设每行前后没有多余的空格字符。</p>
44+
45+
<p><strong>示例:</strong></p>
46+
47+
<p>假设&nbsp;<code>file.txt</code>&nbsp;内容如下:</p>
48+
49+
<pre>987-123-4567
50+
123 456 7890
51+
(123) 456-7890
52+
</pre>
53+
54+
<p>你的脚本应当输出下列有效的电话号码:</p>
55+
56+
<pre>987-123-4567
57+
(123) 456-7890
58+
</pre>
59+
60+
-->
61+
62+
63+
# Read from the file file.txt and output all valid phone numbers to stdout.
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!--
2+
<p>Given a text file <code>file.txt</code>, transpose its content.</p>
3+
4+
<p>You may assume that each row has the same number of columns and each field is separated by the <code>' '</code> character.</p>
5+
6+
<p>
7+
For example, if <code>file.txt</code> has the following content:
8+
<pre>
9+
name age
10+
alice 21
11+
ryan 30
12+
</pre>
13+
</p>
14+
15+
<p>
16+
Output the following:
17+
<pre>
18+
name alice ryan
19+
age 21 30
20+
</pre>
21+
</p><p>给定一个文件&nbsp;<code>file.txt</code>,转置它的内容。</p>
22+
23+
<p>你可以假设每行列数相同,并且每个字段由&nbsp;<code>&#39; &#39;</code> 分隔.</p>
24+
25+
<p><strong>示例:</strong></p>
26+
27+
<p>假设&nbsp;<code>file.txt</code>&nbsp;文件内容如下:</p>
28+
29+
<pre>name age
30+
alice 21
31+
ryan 30
32+
</pre>
33+
34+
<p>应当输出:</p>
35+
36+
<pre>name alice ryan
37+
age 21 30
38+
</pre>
39+
<p>给定一个文件&nbsp;<code>file.txt</code>,转置它的内容。</p>
40+
41+
<p>你可以假设每行列数相同,并且每个字段由&nbsp;<code>&#39; &#39;</code> 分隔.</p>
42+
43+
<p><strong>示例:</strong></p>
44+
45+
<p>假设&nbsp;<code>file.txt</code>&nbsp;文件内容如下:</p>
46+
47+
<pre>name age
48+
alice 21
49+
ryan 30
50+
</pre>
51+
52+
<p>应当输出:</p>
53+
54+
<pre>name alice ryan
55+
age 21 30
56+
</pre>
57+
58+
-->
59+
60+
61+
# Read from the file file.txt and print its transposed content to stdout.

bash/195.Tenth Line(第十行).sh

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<!--
2+
<p>How would you print just the 10th line of a file?</p>
3+
4+
<p>For example, assume that <code>file.txt</code> has the following content:</p>
5+
<pre>
6+
Line 1
7+
Line 2
8+
Line 3
9+
Line 4
10+
Line 5
11+
Line 6
12+
Line 7
13+
Line 8
14+
Line 9
15+
Line 10
16+
</pre>
17+
18+
Your script should output the tenth line, which is:
19+
<pre>
20+
Line 10
21+
</pre>
22+
23+
<p class="showspoilers"><a href="#" onclick="showSpoilers(this); return false;">[show hint]</a></p>
24+
<div class="spoilers"><b>Hint:</b><br />
25+
1. If the file contains less than 10 lines, what should you output?<br>
26+
2. There's at least three different solutions. Try to explore all possibilities.
27+
</div><p>给定一个文本文件&nbsp;<code>file.txt</code>,请只打印这个文件中的第十行。</p>
28+
29+
<p><strong>示例:</strong></p>
30+
31+
<p>假设&nbsp;<code>file.txt</code> 有如下内容:</p>
32+
33+
<pre>Line 1
34+
Line 2
35+
Line 3
36+
Line 4
37+
Line 5
38+
Line 6
39+
Line 7
40+
Line 8
41+
Line 9
42+
Line 10
43+
</pre>
44+
45+
<p>你的脚本应当显示第十行:</p>
46+
47+
<pre>Line 10
48+
</pre>
49+
50+
<p><strong>说明:</strong><br>
51+
1. 如果文件少于十行,你应当输出什么?<br>
52+
2. 至少有三种不同的解法,请尝试尽可能多的方法来解题。</p>
53+
<p>给定一个文本文件&nbsp;<code>file.txt</code>,请只打印这个文件中的第十行。</p>
54+
55+
<p><strong>示例:</strong></p>
56+
57+
<p>假设&nbsp;<code>file.txt</code> 有如下内容:</p>
58+
59+
<pre>Line 1
60+
Line 2
61+
Line 3
62+
Line 4
63+
Line 5
64+
Line 6
65+
Line 7
66+
Line 8
67+
Line 9
68+
Line 10
69+
</pre>
70+
71+
<p>你的脚本应当显示第十行:</p>
72+
73+
<pre>Line 10
74+
</pre>
75+
76+
<p><strong>说明:</strong><br>
77+
1. 如果文件少于十行,你应当输出什么?<br>
78+
2. 至少有三种不同的解法,请尝试尽可能多的方法来解题。</p>
79+
80+
-->
81+
82+
83+
# Read from the file file.txt and output the tenth line to stdout.

c/1.Two Sum(两数之和).c

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
<p>Given an array of integers, return <strong>indices</strong> of the two numbers such that they add up to a specific target.</p>
3+
4+
<p>You may assume that each input would have <strong><em>exactly</em></strong> one solution, and you may not use the <em>same</em> element twice.</p>
5+
6+
<p><strong>Example:</strong></p>
7+
8+
<pre>
9+
Given nums = [2, 7, 11, 15], target = 9,
10+
11+
Because nums[<strong>0</strong>] + nums[<strong>1</strong>] = 2 + 7 = 9,
12+
return [<strong>0</strong>, <strong>1</strong>].
13+
</pre>
14+
15+
<p>&nbsp;</p>
16+
<p>给定一个整数数组和一个目标值,找出数组中和为目标值的<strong>两个</strong>数。</p>
17+
18+
<p>你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用。</p>
19+
20+
<p><strong>示例:</strong></p>
21+
22+
<pre>给定 nums = [2, 7, 11, 15], target = 9
23+
24+
因为 nums[<strong>0</strong>] + nums[<strong>1</strong>] = 2 + 7 = 9
25+
所以返回 [<strong>0, 1</strong>]
26+
</pre>
27+
<p>给定一个整数数组和一个目标值,找出数组中和为目标值的<strong>两个</strong>数。</p>
28+
29+
<p>你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用。</p>
30+
31+
<p><strong>示例:</strong></p>
32+
33+
<pre>给定 nums = [2, 7, 11, 15], target = 9
34+
35+
因为 nums[<strong>0</strong>] + nums[<strong>1</strong>] = 2 + 7 = 9
36+
所以返回 [<strong>0, 1</strong>]
37+
</pre>
38+
*/
39+
40+
41+
/**
42+
* Note: The returned array must be malloced, assume caller calls free().
43+
*/
44+
int* twoSum(int* nums, int numsSize, int target) {
45+
46+
}

0 commit comments

Comments
 (0)