规则名称
东南短码21
规则实现
// The following script is executed by Node.js v14.21.3.
/**
* Calculate the length of the submitted code being counted.
* @param {string} code The content of submitted code.
* @param {string} lang The abbr. of the language used by the code.
* @returns {number} the length of the submitted code being counted
*/
function calcCodeLength(code, lang) { // Only support Java/C/Python/Kotlin/Nodejs
lang = lang.toLowerCase();
let isC = lang.startsWith('c');
let isJava = lang.startsWith('j');
code = code.replace(/\r\n/g,'\n');
if (isC) {
return code.split('\n').map(x => {
let y = x.trim();
if (y.startsWith('#')) y += '\n';
return y;
}).join('').length;
} else if (isJava) return code.split('\n').map(x => x.trim()).join('').length;
else if (lang.startsWith('py')) return code.length * 2; // 2021 Python special rule
else return code.length; // Like Kotlin/Nodejs
}
/**
* Calculate the player's score for one problem.
* @param {number} len The shortest code length of this problem for this player.
* @param {number} minLen The shortest code length of this problem among all players.
* @returns {number} The score of this problem for this player, can be float.
*/
function calcCodeScore(len, minLen) {
return Math.pow(100, Math.sqrt(minLen / len));
}