Last active
December 21, 2017 04:06
-
-
Save sumimakito/d8bebc53a838fbaef67963e20e5e7569 to your computer and use it in GitHub Desktop.
解决一些评教难题。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var i; | |
var j; | |
var groupA = []; | |
var groupB = []; | |
var groupC = []; | |
var scoreTable = []; | |
// input a mess to get a Pure Array | |
function copyArray(src) { | |
var dstArray_ = []; | |
for (var i_ = 0; i_ < src.length; i_++) { | |
dstArray_.push(src[i_]); | |
} | |
return dstArray_; | |
} | |
function removeHead(src) { | |
for (var i_ = 0; i_ < src.length; i_++) { | |
for (var j_ = 0; j_ < src[i_].length; j_++) { | |
src[i_][j_].shift(); | |
} | |
} | |
return src; | |
} | |
function simulateClick(group, idx, section, score) { | |
group[idx][section][score].querySelectorAll('input')[0].click(); | |
} | |
/* | |
* Function to solve the problem that two different teachers/professors | |
* cannot get the same score. | |
* | |
* Examples of the score change after each nextScroll() call. | |
* [0, 0, 0, ..., 0, 0, 0, 0] | |
* [0, 0, 0, ..., 0, 0, 0, 1] | |
* [0, 0, 0, ..., 0, 0, 1, 1] | |
* ... | |
* [0, 1, 1, ..., 1, 1, 1, 1] | |
* [1, 1, 1, ..., 1, 1, 1, 1] | |
* [1, 1, 1, ..., 1, 1, 1, 2] | |
* [1, 1, 1, ..., 1, 1, 2, 2] | |
* ... | |
* | |
*/ | |
function nextScore(score) { | |
var next_ = score[0] + 1; | |
for (var i_ = score.length - 1; i_ >= 0; i_--) { | |
if (score[i_] < next_) { | |
score[i_] = next_; | |
break; | |
} | |
} | |
return score; | |
} | |
var sectionCount = document.querySelectorAll('li.dxt').length; | |
var allRows = copyArray(document.querySelectorAll('li.dxt > table > tbody > tr')); | |
// the initial score table | |
scoreTable.length = sectionCount; | |
scoreTable.fill(0); | |
// disassemble and reorder the elements in the tables | |
for (i = 0; i < allRows.length; i += sectionCount) { | |
var section = allRows.slice(i, i + sectionCount); | |
for (j = 0; j < 3; j++) { | |
if (groupA[j] === undefined) { | |
groupA.push([copyArray(section[j].children)]); | |
} else { | |
groupA[j].push(copyArray(section[j].children)); | |
} | |
} | |
for (; j < 3 + 5; j++) { | |
if (groupB[j - 3] === undefined) { | |
groupB.push([copyArray(section[j].children)]); | |
} else { | |
groupB[j - 3].push(copyArray(section[j].children)); | |
} | |
} | |
for (; j < section.length; j++) { | |
if (groupC[j - 3 - 5] === undefined) { | |
groupC.push([copyArray(section[j].children)]); | |
} else { | |
groupC[j - 3 - 5].push(copyArray(section[j].children)); | |
} | |
} | |
} | |
// first element is useless | |
groupA = removeHead(groupA); | |
groupB = removeHead(groupB); | |
groupC = removeHead(groupC); | |
for (i = 0; i < groupA.length; i++) { | |
for (j = 0; j < groupA[i].length; j++) { | |
simulateClick(groupA, i, j, scoreTable[j]); | |
} | |
nextScore(scoreTable); | |
} | |
// apply a dirty patch, since next level has a score limit | |
nextScore(scoreTable); | |
nextScore(scoreTable); | |
nextScore(scoreTable); | |
for (i = 0; i < groupB.length; i++) { | |
for (j = 0; j < groupB[i].length; j++) { | |
simulateClick(groupB, i, j, scoreTable[j]); | |
} | |
nextScore(scoreTable); | |
} | |
// apply a dirty patch, since next level has a score limit | |
nextScore(scoreTable); | |
for (i = 0; i < groupC.length; i++) { | |
for (j = 0; j < groupC[i].length; j++) { | |
simulateClick(groupC, i, j, scoreTable[j]); | |
} | |
nextScore(scoreTable); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment