编写一个函数,计算字符串中含有的不同字符的个数。字符在 ASCII 码范围内( 0~127 ,包括 0 和 127 ),换行表示结束符,不算在字符里。不在范围内的不作统计。多个相同的字符只计算一次
例如,对于字符串 abaca 而言,有 a、b、c 三种不同的字符,因此输出 3 。
数据范围:
输入一行没有空格的字符串。
输出 输入字符串 中范围在(0~127,包括0和127)字符的种数。
abc
3
aaa
1
const readline = require('readline') var rl = readline.createInterface({ input:process.stdin, output:process.stdout }) var str = '' rl.on('line',(line)=>{ str = line }) rl.on('close',()=>{ var arr = str.split('') var s = new Set(arr.reverse()) var arr2 = [...s] console.log(arr2.length) })
const readline = require('readline') const rl = readline.createInterface({ input: process.stdin, output: process.stdout }) let inputArr = [] rl.on('line', function(input){ inputArr.push(input) let res = inputArr[0].split('') let result = res.reduce( (pre, cur) => { if (!pre.includes(cur)){ pre.push(cur) } return pre }, []) console.log(result.length) inputArr = [] })
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.on('line', function (line) { let set=new Set() for(let i=0;i<line.length;i++){ let c=line.charAt(i) set.add(c) } console.log(set.size) });
while(line=readline()){ var arr=line.split('') var arr2=[] var num=0; arr.forEach(item=>{ if(!arr2.includes(item)){ arr2.push(item) num++ } }) console.log(num) }
var s = readline() let arr = s.split('').filter(s => { return s.charCodeAt()>-1&& s.charCodeAt()<128 }) console.log(Array.from(new Set(arr)).length)
const str = readline(); console.log(new Set(str.split('')).size);
var line=readline(); var arr=line.split(''); var arr1=[]; for(let i=0;i<arr.length;i++){ if(arr1.indexOf(arr[i])==-1){ arr1.push(arr[i]); } //return arr1; } console.log(arr1.length)
while (line = readline()) { let countArr = []; let outputArr = []; for (let i = 0; i < line.length; i++) { let temp = line.charCodeAt(i); if (temp >= 0 && temp <= 127) { countArr.push(line[i]); }; }; outputArr = [...new Set(countArr)]; console.log(outputArr.length); }
let str = readline(); let count = Array.from(new Set(str.split('').map(s => s.charCodeAt()))).filter(f => { return f > 0 && f < 127 }).length; console.log(count);