Skip to content

Commit eadd1a9

Browse files
committed
add 基础编程题目集
1 parent 8478a59 commit eadd1a9

File tree

52 files changed

+177
-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.

52 files changed

+177
-0
lines changed

READMEBuild.py

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
'name': u'中国大学MOOC-陈越、何钦铭-数据结构-起步能力自测题',
2323
'folderName': u'中国大学MOOC-陈越、何钦铭-数据结构-起步能力自测题',
2424
'url': '',
25+
},
26+
{
27+
'name': u'基础编程题目集',
28+
'folderName': u'基础编程题目集',
29+
'url': '',
2530
}
2631
]
2732

@@ -48,6 +53,7 @@ class CodeType:
4853
CPLUSPLUS = 1
4954
PYTHON = 2
5055
JAVA = 4
56+
C = 5
5157

5258
@staticmethod
5359
def getCodeType(ext):
@@ -57,6 +63,8 @@ def getCodeType(ext):
5763
return CodeType.PYTHON
5864
elif ext == '.java':
5965
return CodeType.JAVA
66+
elif ext == '.c':
67+
return CodeType.C
6068

6169
class Table(object):
6270
def __init__(self, folderName, name, url):
@@ -98,6 +106,8 @@ def __str__(self):
98106
codeUrl += '[`Python`](%s/%s_%s.py)' % (githubUrl, self.id, self.name.replace(' ', '%20'))
99107
if self.code & CodeType.JAVA:
100108
codeUrl += '[`Java`](%s/%s_%s.java)' % (githubUrl, self.id, self.name.replace(' ', '%20'))
109+
if self.code & CodeType.C:
110+
codeUrl += '[`C`](%s/%s_%s.c)' % (githubUrl, self.id, self.name.replace(' ', '%20'))
101111
ret = u'| %s | %s | %s |' % (self.id, self.name, codeUrl)
102112
return ret
103113

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
void Print_Factorial ( const int N )
2+
{
3+
if (N < 0)
4+
{
5+
printf("Invalid input");
6+
return;
7+
}
8+
int c[20001];
9+
c[0] = 1;
10+
int digit = 1;
11+
for (int i = 2; i <= N; i++)
12+
{
13+
int num = 0;
14+
for (int d = 0; d < digit; d++)
15+
{
16+
num = c[d] * i + num;
17+
c[d] = num % 10;
18+
num /= 10;
19+
}
20+
while (num)
21+
{
22+
c[digit] = num % 10;
23+
num /= 10;
24+
digit++;
25+
}
26+
}
27+
for (int i = digit-1; i >= 0; i--)
28+
printf("%d", c[i]);
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
ElementType Median(ElementType A[], int N)
2+
{
3+
ElementType aux[MAXN];
4+
for (int i = 0; i < N; i++) aux[i] = A[i];
5+
merge_help_sort(aux, A, 0, N - 1);
6+
return A[N/2];
7+
}
8+
9+
void merge_help_sort(ElementType src[], ElementType dst[], int lo, int hi) {
10+
if (hi <= lo) return;
11+
int mid = lo + ((hi - lo) >> 1);
12+
merge_help_sort(dst, src, lo, mid);
13+
merge_help_sort(dst, src, mid + 1, hi);
14+
merge(src, dst, lo, mid, hi);
15+
}
16+
17+
void merge(ElementType src[], ElementType dst[], int lo, int mid, int hi) {
18+
int i = lo, j = mid + 1;
19+
for (int k = lo; k <= hi; k++) {
20+
if (i > mid) dst[k] = src[j++];
21+
else if (j > hi) dst[k] = src[i++];
22+
else if (src[i] < src[j]) dst[k] = src[i++];
23+
else dst[k] = src[j++];
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int even( int n )
2+
{
3+
return n % 2 == 0;
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
int Search_Bin(SSTable T, KeyType k)
2+
{
3+
int lo = 1, hi = T.length;
4+
while (lo < hi)
5+
{
6+
int mid = lo + (hi-lo) / 2;
7+
if (T.R[mid].key == k) return mid;
8+
else if (T.R[mid].key < k) lo = mid+1;
9+
else hi = mid-1;
10+
}
11+
return 0;
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
void PrintN(int n)
2+
{
3+
for (int i = 1; i <= n; i++)
4+
{
5+
printf("%d\n", i);
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
double f(int n, double a[], double x)
2+
{
3+
double sum = 0;
4+
double base = 1;
5+
for (int i = 0; i <= n; i++) {
6+
sum += a[i] * base;
7+
base *= x;
8+
}
9+
return sum;
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
int Sum (int List[], int N)
2+
{
3+
int sum = 0;
4+
for (int i = 0; i < N; i++)
5+
{
6+
sum += List[i];
7+
}
8+
return sum;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ElementType Average(ElementType S[], int N)
2+
{
3+
ElementType sum = 0;
4+
for (int i = 0; i < N; i++)
5+
{
6+
sum += S[i];
7+
}
8+
return sum / N;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ElementType Max(ElementType S[],int N)
2+
{
3+
ElementType result = S[0];
4+
for (int i = 1; i < N; i++)
5+
{
6+
result = S[i] > result ? S[i] : result;
7+
}
8+
return result;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
int FactorialSum( List L )
2+
{
3+
int sum = 0;
4+
while (L != NULL)
5+
{
6+
int fac = 1;
7+
for (int i = L->Data; i >= 2; i--)
8+
{
9+
fac *= i;
10+
}
11+
sum += fac;
12+
L = L->Next;
13+
}
14+
return sum;
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
int IsTheNumber (const int N)
2+
{
3+
int n = N;
4+
int b = (int)sqrt(n);
5+
int sq = b*b == n;
6+
int same = 0;
7+
int bit[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
8+
do {
9+
if (bit[n % 10] == 1) {
10+
same = 1;
11+
break;
12+
}
13+
bit[n % 10] = 1;
14+
n /= 10;
15+
} while (n != 0);
16+
return sq && same;
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
int Factorial( const int N )
2+
{
3+
int result = 1;
4+
for (int i = 2; i <= N; i++)
5+
{
6+
result *= i;
7+
}
8+
return N >= 0 ? result : 0;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
int Count_Digit ( const int N, const int D )
2+
{
3+
int n = abs(N);
4+
int countD = 0;
5+
do
6+
{
7+
if (n % 10 == D) countD++;
8+
n /= 10;
9+
} while (n != 0);
10+
return countD;
11+
}
318 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
782 Bytes
Binary file not shown.
528 Bytes
Binary file not shown.
854 Bytes
Binary file not shown.
Binary file not shown.
398 Bytes
Binary file not shown.
Binary file not shown.
472 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
948 Bytes
Binary file not shown.
1.32 KB
Binary file not shown.
Binary file not shown.
534 Bytes
Binary file not shown.
156 Bytes
Binary file not shown.
484 Bytes
Binary file not shown.
426 Bytes
Binary file not shown.
Binary file not shown.
346 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
606 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
216 Bytes
Binary file not shown.
708 Bytes
Binary file not shown.
Binary file not shown.
260 Bytes
Binary file not shown.
226 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)