For interview algorithm questions, arrange 1, 2, 3, 4... according to the following rules

Arrange 1, 2, 3, 4... according to the following rules (the first row is special), for example, the number 3 is in the first row and column C, then the number 2013 is in which row and column... Specifically as shown below

Solve the problem as follows

function main(args) {
  lie = ""; //列
  hang = 0; //行
  num = 2013;
  fournum = parseInt(num / 4); //包含多少个
  mnum = num % 4; //目标数模4
  hang = fournum;
  if (mnum > 0) {
    hang = hang + 1;
  }
  jo = hang % 2; //余数等于1是奇数
  if (mnum == 3) {
    lie = "C";
  } else if (jo == 1) { //奇数
    if (mnum == 0) {
      lie = "D";
    } else if (mnum == 1) {
      lie = "E";
    } else if (mnum == 2) {
      lie = "B";
    }
  } else if (jo == 0) { //
    if (mnum == 0) {
      lie = "B";
    } else if (mnum == 2) {
      lie = "D";
    } else if (mnum == 1) {
      lie = "A";
    }
  }
  // hang = hang-1;
  console.log(num + "在第" + hang + "行,第" + lie + "列")
}
main()

Guess you like

Origin blog.csdn.net/qq_39704803/article/details/125005818