[关闭]
@Humbert 2017-12-17T00:50:19.000000Z 字数 2133 阅读 805

C quiz

C语言测试,不可使用C++特性编写程序。
测试共有5题,限时3小时。

A.打印素数

输出100以内的所有素数。
根据算法效率来计算分数。

INPUT:无

OUTPUT:

  1. 2 3 5 ... 97

B.进制转换

写一个可以将2进制正整数(小于1000位)转化为10进制数的函数。

测试用例一:
INPUT1:

  1. 1010101101010101010101010101010101010101010101110001101010111011010010100101010101010101010101010101010101010101011

OUTPUT1:

测试用例二:
INPUT2:

  1. 111111111111111111111111111000000000000000000000000001111111111111111111111111111111111111111100000000000000000000000000000000000111111111111111111111111111111111111100000000000000000000000000001

OUTPUT2:

INPUT3 :

  1. 1011101010101011011101001011101100111101001010100101001010111001010101011101001

OUTPUT:

C. Search a 2D Matrix

写一个程序来在一个m * n 矩阵中寻找一个数字。
这个矩阵有以下性质:

考虑使用改矩阵的特性来实现一个较为高效的算法

输入格式:
M(行)
N(列)
Target(搜索的目标)
M行数字,每行有N个数字.
输出格式:
true(找到了)
false(未找到)

Input Data1:

  1. 3
  2. 4
  3. 3
  4. 1 3 5 7
  5. 10 11 16 20
  6. 23 30 34 50

Output:

  1. true

Input Data2:

  1. 1
  2. 2
  3. 3
  4. 1 3

Output:

  1. true

Input Data3:

  1. 3
  2. 3
  3. 20
  4. 1 3 5
  5. 7 9 11
  6. 13 15 17
  7. 19 21 23

Output:

  1. false

Input Data4:

  1. 2
  2. 2
  3. 8
  4. 1 2
  5. 3 4

Output:

  1. false

D.合并序列

合并两个已增序排列的序列,要求合并后的序列仍然保持增序。(有考虑效率者或使用更高级数据结构者可加分)

输入格式
每个测试用例有两个序列,每个序列第一行的值为该序列有N个数字,接下来N个数字为该序列的元素.

输出格式
一个有序序列

INPUT1:

  1. 4
  2. 1 5 6 9
  3. 6
  4. 2 5 7 10 12 15

OUTPUT1:

  1. 1 2 5 5 6 7 9 10 12 15

测试用例二:

INPUT2:

  1. 5
  2. 5 8 9 10 23
  3. 3
  4. 2 5 7

OUTPUT2:

  1. 2 5 5 7 8 9 10 23

INPUT3:

  1. 5
  2. 1 3 5 10 20
  3. 5
  4. 2 4 6 8 19

OUTPUT3:

  1. 1 2 3 4 5 6 8 10 19 20

E.Target Sum

description :
You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol.

Input :

Each input file contains one test case.
Print in the first line the number of the non-negative integers and the target.
Print in the second line each number :

  1. num target
  2. a0 a1 a2 ····· a(num-1)

Output :
Print how many ways to assign symbols to make sum of integers equal to target S.

  1. ways

Note :

  1. The length of the given array is positive and will not exceed 20.
  2. The sum of elements in the given array will not exceed 1000.
  3. Your output answer is guaranteed to be fitted in a 32-bit integer.

Example1 :

Input:

  1. 5 3
  2. 1 1 1 1 1

Output:

  1. 5

Explanation:

-1+1+1+1+1 = 3
+1-1+1+1+1 = 3
+1+1-1+1+1 = 3
+1+1+1-1+1 = 3
+1+1+1+1-1 = 3
There are 5 ways to assign symbols to make the sum of nums be target 3.

Example2 :

Input:

  1. 5 3
  2. 1 2 3 4 5

Output:

  1. 3

Explanation:

-1-2-3+4+5 = 3
+1-2+3-4+5 = 3
-1+2+3+4-5 = 3
There are 3 ways to assign symbols to make the sum of nums be target 3.

Example3 :

Input:

  1. 5 5
  2. 1 2 3 4 5

Output:

  1. 3

Explanation:

+1+2+3+4-5 = 5
-1+2+3-4+5 = 5
+1-2-3+4+5 = 5

There are 3 ways to assign symbols to make the sum of nums be target 5.

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注