网易内推前端3道题---彩砖01串独立生活时间
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了网易内推前端3道题---彩砖01串独立生活时间相关的知识,希望对你有一定的参考价值。
1.
var readline = require(‘readline‘);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal:false
});
rl.on(‘line‘, function(line){ // javascript每行数据的回调接口
console.log(num(line));
});
function num(str){
var len = 0;
var s = new Set(str.split(‘‘));
if(s.size<=2) len = s.size;
return len;
}
2.
var readline = require(‘readline‘);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal:false
});
rl.on(‘line‘, function(line){ // javascript每行数据的回调接口
console.log(num(line));
});
function num(str){
var len = 1;
var max = 1;
for(var i=1;i<str.length;i++){
if(str[i]!=str[i-1]){
len++;
}else{
len = 1;
}
max>len?‘‘:max=len;
}
3.
var readline = require(‘readline‘);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal:false
});
rl.on(‘line‘, function(line){ // javascript每行数据的回调接口
console.log(num(line));
});
function num(str){
var len = 0;
var arr = str.split(" ");
var x = parseInt(arr[0]);
var f = parseInt(arr[1]);
var d = parseInt(arr[2]);
var p = parseInt(arr[3]);
if(d/x<=f){
len = Math.floor(d/x);
}else{
d=d-f*x;
len=f+Math.floor(d/(x+p));
}
return len;
}
以上是关于网易内推前端3道题---彩砖01串独立生活时间的主要内容,如果未能解决你的问题,请参考以下文章