深信服笔试
- 第一题,这个感觉是在考察你的api能力和细节
const sss = readline() let str = '', ans = '', f = true for (let i = 0; i < sss.length; i++) { if (f) { if (sss[i] === ' ') { f = false continue } str += sss[i] } else { ans += sss[i] } } str = JSON.stringify(new Date(+str)) const arr = str.split('T') let left = arr[0].split('-') let year = left[0].slice(1), mon = left[1], day = left[2] let right = arr[1].split('.')[0].split(':') let hour = right[0], min = right[1], second = right[2] if (mon.startsWith('0')) mon = mon.slice(1) if (day.startsWith('0')) day = day.slice(1) if (year.startsWith('0')) year = year.slice(1) if (hour.startsWith('0')) hour = hour.slice(1) if (min.startsWith('0')) min = min.slice(1) if (second.startsWith('0')) second = second.slice(1) const keyarr = ['yyyy', 'MM', 'dd', 'HH', 'mm', 'ss'] const valuearr = [year, mon, day, hour, min, second] for (let i = 0; i < keyarr.length; i++) { while (ans.indexOf(keyarr[i]) !== -1) { ans = ans.replace(keyarr[i], valuearr[i]) } } print(ans)
2.不知道为什么,80%
const arr = readline().split(' ').map(x => +x) let n = arr[0]//客人数量 let t = arr[1]//时间 const all = Array(n).fill(0).map((item, index) => index) let start = 0 while (all.length > 1) { start = (start + t) % (all.length) all.splice(start, 1) } print(all[0])
3.滑动窗口就行
const arr = readline().split(' ').map(x => +x) const k = arr.splice(arr.length - 1, 1) if (arr.reduce((a, b) => a + b, 0) < k) print(0) //滑动窗口 let left = 0, right = 0, min = Infinity, sum = 0 let ans = [] while (right < arr.length) { sum += arr[right] while (sum >= k) { if ((right - left + 1) < min) { min = right - left + 1 ans = [] for (let i = left; i <= right; i++) { ans.push(i) } ans = ans.join(' ') } sum -= arr[left] left++ } right++ } print(ans)#深信服笔试题##前端#