网易内推前端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.
![](https://images2017.cnblogs.com/blog/923649/201708/923649-20170813090338460-2118090611.png)
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.
![](https://images2017.cnblogs.com/blog/923649/201708/923649-20170813090533445-2122329603.png)
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;
}