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;
}