Skip to content

Commit 7f16adf

Browse files
committed
add readme.sh script to help to generate the content in README.md for each problem
1 parent 2c9f3c2 commit 7f16adf

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

scripts/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,16 @@ The comments would be generated by above examples as below:
4444
4545
4646
```
47+
48+
### readme.sh
49+
50+
`readme.sh` - it's used to generate the table item in README.md
51+
52+
For example:
53+
54+
```
55+
$ ./readme.sh ../algorithms/cpp/nextPermutation/nextPermutation.cpp
56+
|31|[Next Permutation](https://oj.leetcode.com/problems/next-permutation/) | [C++](./algorithms/cpp/nextPermutation/nextPermutation.cpp)|Medium|
57+
```
58+
59+

scripts/readme.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
4+
function usage()
5+
{
6+
7+
echo -e "Usage: ${0} [file]"
8+
echo -e ""
9+
echo -e "Example:"
10+
echo -e ""
11+
echo -e " ${0} ./LargestNumber.cpp"
12+
echo -e ""
13+
}
14+
15+
16+
17+
if [ $# -lt 1 ] || [[ ! -f ${1} ]]; then
18+
usage
19+
exit 255
20+
fi
21+
22+
DIR=`cd $(dirname ${1}) && pwd -P`
23+
FILE=${DIR}/$(basename ${1})
24+
25+
URL=`grep Source ${FILE} | awk '{print $4}'`
26+
title_str=`xidel ${URL} -q -e "css('div.question-title h3')"`
27+
NUM=`echo ${title_str} | awk -F '.' '{print $1}'`
28+
TITLE=`echo ${title_str} | awk -F '.' '{print $2}' | sed -e 's/^[[:space:]]*//'`
29+
DIFFCULT=`xidel ${URL} -q -e "css('.question-info')" | grep Difficulty | awk '{print $2}'`
30+
31+
FILE=`echo ${FILE} | sed "s/.*\/algorithms/\.\/algorithms/"`
32+
33+
echo "|${NUM}|[${TITLE}](${URL}) | [C++](${FILE})|${DIFFCULT}|"

0 commit comments

Comments
 (0)