当前位置:七七学习网文档大全求职指南求职笔试面试笔试题目IT公司笔试常考的算法题» 正文

IT公司笔试常考的算法题

[10-10 21:21:19]   来源:http://www.77xue.com  笔试题目   阅读:8993
概要:{'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
IT公司笔试常考的算法题,标签:驾照笔试题目,腾讯笔试题目,http://www.77xue.com

  {'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 ? ' ' : '\n');

  }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("\nNo.%d:\n", ++iCount);

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

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

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

  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]

  Set(iRowNo);

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

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9]  下一页


Tag:笔试题目驾照笔试题目,腾讯笔试题目求职指南 - 求职笔试面试 - 笔试题目
联系我们 | 网站地图 | 范文大全 | 管理知识 | 教学教育 | 作文大全 | 语句好词
Copyright http://www.77xue.com--(七七学习网) All Right Reserved.
1 2 3 4 5 6 7 8 9 10