简单算法题
作者:互联网
1.有五张牌,每张牌上的数字都是0-9的任意数字
2.如果任意三张牌的和可以被10整除,则考虑一下情况
1)如果剩余两张牌的和可以被10整除,则输出10
2)如果剩余两张牌的和被10整除余1,则输出1
3)如果剩余两张牌的和被10整除余2,则输出2
4)如果剩余两张牌的和被10整除余3,则输出3
5)如果剩余两张牌的和被10整除余4,则输出4
。。。。
9)如果剩余两张牌的和被10整除余9,则输出9
3.如果任意三张都不能被10整除,则输出0
输入:数组a[],包含五个数字
输出:输出类型
function outNum(arr){
let oldArr = arr
let newArr = []
a1 = Math.floor(Math.random()*arr.length)
newArr.push(oldArr[a1])
oldArr.splice(a1, 1)
a2 = Math.floor(Math.random()*arr.length)
newArr.push(oldArr[a2])
oldArr.splice(a2, 1)
a3 = Math.floor(Math.random()*arr.length)
newArr.push(oldArr[a3])
oldArr.splice(a3, 1)
if(newArr[a1] + newArr[a2] + newArr[a2] % 10 !=0){
console.log(oldArr)
console.log(newArr)
return 0
}else {
console.log(newArr[a1] + newArr[a2] + newArr[a2])
if(oldArr[0]+oldArr[1] %10 == 1){
return 1
}else if (oldArr[0]+oldArr[1] %10 == 2) {
return 2
}else if (oldArr[0]+oldArr[1] %10 == 3) {
return 3
}else if (oldArr[0]+oldArr[1] %10 == 4) {
return 4
}else if (oldArr[0]+oldArr[1] %10 == 5) {
return 5
}else if (oldArr[0]+oldArr[1] %10 == 6) {
return 6
}else if (oldArr[0]+oldArr[1] %10 == 7) {
return 7
}else if (oldArr[0]+oldArr[1] %10 == 8) {
return 8
}else if (oldArr[0]+oldArr[1] %10 == 9) {
return 9
}else if (oldArr[0]+oldArr[1] %10 == 0) {
return 10
}
}
}
标签:10,return,newArr,else,算法,简单,整除,oldArr 来源: https://blog.csdn.net/qq_45415773/article/details/118053805