腾讯笔试题

时间:2022-07-10 06:12:58 笔试 我要投稿
  • 相关推荐

关于腾讯笔试题

部分IT公司笔试算法题

关于腾讯笔试题

1、将一整数逆序后放入一数组中(要求递归实现)

void convert(int *result, int n) {

if(n>=10)

convert(result+1, n/10);

*result = n%10;

}

int main(int argc, char* argv[]) {

int n = 123456789, result[20] = { };

convert(result, n);

printf("%d:", n);

for (int i = 0; i < 9; i++)

printf("%d", result);

}

2、求高于平均分的学生学号及成绩(学号和成绩人工输入)

double find(int total, int n) {

int number, score, average;

scanf("%d", &number);

if(number != 0) {

scanf("%d", &score);

average = find(total+score, n+1);

if(score >= average)

printf("%d:%d ", number, score);

return average;

} else {

printf("Average=%d ", total/n);

return total/n;

}

}

int main(int argc, char* argv[]) {

find(0, 0);

}

3、递归实现回文判断(如:abcdedbca就是回文,判断一个面试者对递归理解的简单程序)

int find(char *str, int n) {

if(n<=1) return 1;

else if(str[0]==str[n-1]) return find(str+1, n-2);

else return 0;

}

int main(int argc, char* argv[]) {

char *str = "abcdedcba";

printf("%s: %s ", str, find(str, strlen(str)) ? "Yes" : "No");

}

4、组合问题(从M个不同字符中任取N个字符的所有组合)

void find(char *source, char *result, int n) {

if(n==1) {

while(*source)

printf("%s%c ", result, *source++);

} else {

int i, j;

for(i=0; source != 0; i++);

for(j=0; result[j] != 0; j++);

for(; i>=n; i--) {

result[j] = *source++;

result[j+1] = ;

find(source, result, n-1);

}

}

}

int main(int argc, char* argv[]) {

int const n = 3;

char *source = "ABCDE", result[n + 1] = { 0 };

if (n > 0 && strlen(source) > 0 && n< = strlen(source))

find(source, result, 3);

}

5、分解成质因数(如435234=251*17*17*3*2,据说是华为笔试题)

void prim(int m, int n) {

if(m>n) {

while(m%n != 0) n++;

m /= n;

prim(m, n);

printf("%d*", n);

}

}

int main(int argc, char* argv[]) {

int n = 435234;

printf("%d=", n);

prim(n, 2);

}

6、寻找迷宫的一条出路,o:通路; X:障碍。(大家经常谈到的一个小算法题)

#define MAX_SIZE 8

int H[4] = {0, 1, 0, -1};

int V[4] = { -1, 0, 1, 0 };

char Maze[MAX_SIZE][MAX_SIZE] = { { X, X, X, X, X, X, X, X }, {

o, o, o, o, o, X, X, X }, { X, o, X, X, o,

o, o, X }, { X, o, X, X, o, X, X, o }, { X,

o, X, X, X, X, X, X }, { X, o, X, X, o, o,

o, X }, { X, o, o, o, o, X, o, o }, { X, X,

X, X, X, X, X, X } };

void FindPath(int X, int Y) {

if (X == MAX_SIZE || Y == MAX_SIZE) {

for (int i = 0; i < MAX_SIZE; i++)

for (int j = 0; j < MAX_SIZE; j++)

printf("%c%c", Maze[j], j < MAX_SIZE - 1 ? : );

} else

for (int k = 0; k < 4; k++)

if (X >= 0 && Y >= 0 && Y < MAX_SIZE&& X < MAX_SIZE && o

== Maze[X][Y]) {

Maze[X][Y] = ;

FindPath(X + V[k], Y + H[k]);

Maze[X][Y] = o;

}

}

int main(int argc, char* argv[]) {

FindPath(1, 0);

}

7、随机分配座位,共50个学生,使学号相邻的同学座位不能相邻(早些时候用C

#写的,没有用C改写)。

static void Main(string[] args)

{

int Tmp = 0, Count = 50;

int[] Seats = new int[Count];

bool[] Students = new bool[Count];

System.Random RandStudent=new System.Random();

Students[Seats[0]=RandStudent.Next(0,Count)]=true;

for(int i = 1; i < Count; ) {

Tmp=(int)RandStudent.Next(0,Count);

if((!Students[Tmp])&&(Seats[i-1]-Tmp!=1) && (Seats[i-1] - Tmp) != -1) {

Seats[i++] = Tmp;

Students[Tmp] = true;

}

}

foreach(int Student in Seats)

System.Console.Write(Student + " ");

System.Console.Read();

}

8、求网格中的黑点分布。现有6*7的网格,在某些格子中有黑点,已知各行与各列中有黑点的点数之和,请在这张网格中画出黑点的位置。(这是一网友提出的题目,说是他笔试时遇到算法题)

#define ROWS 6

#define COLS 7

int iPointsR[ROWS] = {2, 0, 4, 3, 4, 0}; // 各行黑点数和的情况

int iPointsC[COLS] = { 4, 1, 2, 2, 1, 2, 1 }; // 各列黑点数和的情况

int iCount, iFound;

int iSumR[ROWS], iSumC[COLS], Grid[ROWS][COLS];

int Set(int iRowNo) {

if (iRowNo == ROWS) {

for (int iColNo = 0; iColNo < COLS && iSumC[iColNo] == iPointsC[iColNo]; iColNo++)

if (iColNo == COLS - 1) {

printf(" No.%d: ", ++iCount);

for (int i = 0; i < ROWS; i++)

for (int j = 0; j < COLS; j++)

printf("%d%c", Grid[j], (j + 1) % COLS ? : );

iFound = 1; // iFound = 1,有解

}

} else {

for (int iColNo = 0; iColNo < COLS; iColNo++) {

if (iPointsR[iRowNo] == 0) {

Set(iRowNo + 1);

} else if (Grid[iRowNo][iColNo] == 0) {

Grid[iRowNo][iColNo] = 1;

iSumR[iRowNo]++;

iSumC[iColNo]++;

if (iSumR[iRowNo] < iPointsR[iRowNo] && iSumC[iColNo]

<= iPointsC[iColNo])

Set(iRowNo);

else if (iSumR[iRowNo] == iPointsR[iRowNo] && iRowNo < ROWS)

Set(iRowNo + 1);

Grid[iRowNo][iColNo] = 0;

iSumR[iRowNo]--;

iSumC[iColNo]--;

}

}

}

return iFound; // 用于判断是否有解

}

int main(int argc, char* argv[]) {

if (!Set(0))

printf("Failure!");

}

9、有4种面值的邮票很多枚,这4种邮票面值分别1, 4, 12, 21,现从多张中最多任取5张进行组合,求取出这些邮票的最大连续组合值。(据说是华为2003年校园招聘笔试题)

#define N 5

#define M 5

int k, Found, Flag[N];

int Stamp[M] = { 0, 1, 4, 12, 21 };

// 在剩余张数n中组合出面值和Value

int Combine(int n, int Value) {

if (n >= 0 && Value == 0) {

Found = 1;

int Sum = 0;

for (int i = 0; i < N && Flag != 0; i++) {

Sum += Stamp[Flag];

printf("%d ", Stamp[Flag]);

}

printf(" Sum=%d ", Sum);

} else

for (int i = 1; i < M && !Found && n > 0; i++)

if (Value - Stamp >= 0) {

Flag[k++] = i;

Combine(n - 1, Value - Stamp);

Flag[--k] = 0;

}

return Found;

}

int main(int argc, char* argv[]) {

for (int i = 1; Combine(N, i); i++, Found = 0)

;

}

10、大整数数相乘的问题。(这是2002年在一考研班上遇到的算法题)

void Multiple(char A[], char B[], char C[]) {

int TMP, In=0, LenA=-1, LenB=-1;

while(A[++LenA] != );

while(B[++LenB] != );

int Index, Start = LenA + LenB - 1;

for(int i=LenB-1; i>=0; i--) {

Index = Start--;

if(B != 0) {

for(int In=0, j=LenA-1; j>=0; j--) {

TMP = (C[Index]-0) + (A[j]-0) * (B - 0) + In;

C[Index--] = TMP % 10 + 0;

In = TMP / 10;

}

C[Index] = In + 0;

}

}

}

int main(int argc, char* argv[]) {

char A[] = "21839244444444448880088888889";

char B[] = "38888888888899999999999999988";

char C[sizeof(A) + sizeof(B) - 1];

for (int k = 0; k < sizeof(C); k++)

C[k] = 0;

C[sizeof(C) - 1] = ;

Multiple(A, B, C);

for (int i = 0; C != ; i++)

printf("%c", C);

}

11、求最大连续递增数字串(如“ads3sl456789DF3456ld345AA”中的“456789”)

int GetSubString(char *strSource, char *strResult) {

int iTmp=0, iHead=0, iMax=0;

for(int Index=0, iLen=0; strSource[Index]; Index++) {

if(strSource[Index] >= 0 && strSource[Index] <= 9 &&

strSource[Index-1]> 0 && strSource[Index] == strSource[Index-1]+

【腾讯笔试题】相关文章:

腾讯cdkey领取方法01-07

腾讯微云怎么搜索资源?04-22

腾讯游戏运营待遇如何08-04

腾讯公益图标怎么永久点亮08-04

怎么点亮腾讯QQ旋风图标08-01

腾讯CDC是否真的解散了?06-27

腾讯爱玩斗战神礼包怎么得05-09

怎么使用腾讯企业邮箱归档04-04

简笔与繁笔教学设计05-27

腾讯QQ2013迷你资讯弹窗怎么删除08-01