标签:length math readline 分享图片 UNC i+1 字符串 javascrip justify
var readline = require(‘readline‘); const rl = readline.createInterface({ input:process.stdin, output:process.stdout }); const lines = []; rl.on(‘line‘,function(line){ lines.push(line); const arr= lines.map((item) => { return +item; }) if(arr.length === arr[0]+1){ let num = arr[0]; for(let i=1;i<=num;i++){ justify(arr[i]); } } }) function justify(num){ var a=num; var sum = 0; var temp =0; while(num>0){ temp=num%10; num=parseInt(num/10); sum+=temp; } if(a%sum===0){ console.log(‘Yes‘) }else{ console.log(‘No‘) } }
只通过30%,待完善
var readline = require(‘readline‘); const rl = readline.createInterface({ input:process.stdin, output:process.stdout }); const lines = []; rl.on(‘line‘,function(line){ lines.push(line); if(lines.length === 2){ var str=lines[0]; var firstindex=0 var result=[]; index = str.indexOf(lines[1],firstindex); while(index>=0){ result.push(index); index = str.indexOf(lines[1],index+lines[1].length); } // 找到的满足字符串P的全部起始位置 console.log(result); var sum=0; var count = 1; for(let i=0;i<result.length-1;i++){ if(result[i+1]-result[i]===lines[1].length){ count++; }else{ sum+=Math.pow(lines[1].length*count,2); count=1; } } sum+=Math.pow(lines[1].length*count,2); console.log(sum); } })
aaa的情况,考虑不周
标签:length math readline 分享图片 UNC i+1 字符串 javascrip justify
原文地址:https://www.cnblogs.com/shenminer/p/9656991.html