爱奇艺前端笔试编程题代码分享
3AC
1.三角形
var inarr = readline().split(" "); for(var i in inarr){ inarr[i] = parseInt(inarr[i]); } inarr.sort(function(x,y){ return x-y; }) inarr[2] = inarr[2]>=(inarr[0]+inarr[1])?(inarr[0]+inarr[1]-1):(inarr[2]); print(inarr[0]+inarr[1]+inarr[2]);2.方块变色
var instr = readline(); var rtotal = instr.match(/R/g).length; var rcount = 0; var t; var n = instr.length; var min = rtotal; for(var i=0;i<n;i++){ if(instr[i]=="R"){ rcount++; } t = rtotal-2*rcount+i+1; if(t<min){ min = t; } } console.log(min);3.repeat比较
var arr = readline().split(" "); var alen = arr[0].length; var blen = arr[2].length; var anum = parseInt(arr[1]); var bnum = parseInt(arr[3]); console.log(comp()); function comp(){ if(alen*anum>blen*bnum){ return 'Greater'; }else if(alen*anum<blen*bnum){ return 'Less'; } var a = arr[0]; var b = arr[2]; for(var i=0;i<anum;i++){ a = a.concat(arr[0]); } for(var i=0;i<bnum;i++){ b = b.concat(arr[2]); } var len = alen*anum; for(var i=0;i<len;i++){ if(parseInt(a[i])>parseInt(b[i])){ return 'Greater'; }else if(parseInt(a[i])<parseInt(b[i])){ return 'Less'; } } return 'Equal'; }
第三题应该能优化
#爱奇艺##前端工程师#