首页
题库
公司真题
专项练习
面试题库
在线编程
面试
面试经验
AI 模拟面试
简历
求职
学习
基础学习课
实战项目课
求职辅导课
专栏&文章
竞赛
搜索
我要招人
发布职位
发布职位、邀约牛人
更多企业解决方案
AI面试、笔试、校招、雇品
HR免费试用AI面试
最新面试提效必备
登录
/
注册
蓝色水晶
2017-09-11 08:03
西安电子科技大学
关注
已关注
取消关注
有没有人做思特沃克的线下作业题,求讨论
有没有人做思特沃克的线下作业题,求讨论
提示
全部评论
推荐
最新
楼层
Horace7
伦敦大学学院 算法工程师
https://github.com/billweasley/BadmintonCourt Java写的 不会写正则,所以语句parse写的特别特别丑... 另外好多地方好像可以改进,总之求交流
点赞
回复
分享
发布于 2017-09-12 20:17
努力给自己一个offer
华南理工大学 前端工程师
JS写的,个人觉得写得比较垃圾,应该有其他更好的方法和优化的方法,不过自己实在是想不出来了,希望有大佬指点一下 (function work() { //程序主类 class Program { constructor(line) { this.reg = /\s*(\w+)\s+(\d{4}-\d{2}-\d{2})\s+(\d{2}:00~\d{2}:00)\s+([ABCD])\s*(C)?\s*/; //匹配字符串格式 this.dateReg = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/; //匹配日期字符串 this.timeReg = /(09|1[0-9]|2[0-2]):00~(09|1[0-9]|2[0-2]):00/; //匹配时间段字符串 this.A = new Court(); this.B = new Court(); this.C = new Court(); this.D = new Court(); this.total = 0; } //程序入口,进行基础判断,并调用相应场地的对应函数 start(str) { if (!str) { return; } else if (/^\s+$/.test(str)) { this.printAll(); } else if (!(this.reg.test(str))) { console.log('> ' + new Error('the booking is invalid!')); return; } else { let res = this.reg.exec(str), id = res[1], date = res[2], time = res[3], court = res[4], cancel = res[5]; //将输入字符串分割,提取信息 let courtObj = { 'A': this.A, 'B': this.B, 'C': this.C, 'D': this.D }; if (!(this.dateReg.test(date))) { //日期格式错误 console.log('> ' + new Error('the booking is invalid!')); return; } else { if (!(this.timeReg.test(time))) { //时间格式错误 console.log('> ' + new Error('the booking is invalid!')); return; } else { if (Number(RegExp.$1) >= Number(RegExp.$2)) { //订场起始时间晚于开始时间 console.log('> ' + new Error('the booking is invalid!')); return; } else { if (!cancel) { //如果没有取消标识符,调用相应的场地对象的order courtObj[court].order(id, date, time); } else { //如果有取消标识符,调用相应的场地对象的cancelOrder courtObj[court].cancelOrder(id, date, time); } } } } } } //所有信息的打印函数 printAll() { console.log('> 收入汇总'); console.log('> ---'); console.log('> 场地:A'); this.A.printItems(); console.log('>'); console.log('> 场地:B'); this.B.printItems(); console.log('>'); console.log('> 场地:C'); this.C.printItems(); console.log('>'); console.log('> 场地:D'); this.D.printItems(); console.log('> ---'); this.total = this.A.total + this.B.total + this.C.total + this.D.total; //在打印时再计算总收入 console.log('> 总计:' + this.total + '元'); } } //场地类,包含场地所有订单、收入等信息 class Court { constructor() { this.orders = []; this.total = 0; } //新增订单时调用的函数 order(id, date, time) { let newTime = time.split('~'), newStart = Number(newTime[0].split(":")[0]), newEnd = Number(newTime[1].split(":")[0]), weekDay = new Date(date).getDay(), price; for (let i = 0; i < this.orders.length; i++) { let nowOrder = this.orders[i]; let currentTime = nowOrder.time.split("~"), currentStart = Number(currentTime[0].split(":")[0]), currentEnd = Number(currentTime[1].split(":")[0]); //取得输入的起始和结束时间 if (date === nowOrder.date && ((newStart >= currentStart && newStart < currentEnd) || (newEnd > currentStart && newEnd <= currentEnd)) && !nowOrder.cancel) { console.log('> ' + new Error('the booking conflicts with existing bookings!')); return; } } let timeSlice = countTimeSlice(newStart, newEnd); let [long1 = 0, long2 = 0, long3 = 0, long4 = 0] = timeSlice; //分别计算输入的时间分别在4个时间段内的长度 //计算新订单所带来的收入 if (weekDay > 0 && weekDay < 6) { price = 30 * long1 + 50 * long2 + 80 * long3 + 60 * long4; } else { price = 40 * long1 + 50 * long2 + (long3 + long4) * 60; } this.total += price; //每次有新订单则更新场地自己的总收入 this.orders.push(new Order(id, date, time, price)); console.log('> Success: the booking is accepted!'); } //取消订单时调用的函数 cancelOrder(id, date, time) { let i = 0; while (this.orders[i]) { let currentOrder = this.orders[i]; let previousPrice = currentOrder.price; if (currentOrder.id === id && currentOrder.time === time && currentOrder.date === date && currentOrder.cancel === false) { let weekDay = new Date(date).getDay(); //每次有订单取消则更新场地自己的总收入 if (weekDay > 0 && weekDay < 6) { currentOrder.price *= 0.5; this.total -= previousPrice * 0.5; } else { currentOrder.price *= 0.25; this.total -= previousPrice * 0.75; } currentOrder.cancel = true; console.log('> Success: the booking is accepted!'); return; } i++; } console.log('> ' + new Error('the booking being cancelled does not exist!')); return; } //各场地的打印函数 printItems() { this.orders.sort(compareFn); let outputStr; for (let i = 0; i < this.orders.length; i++) { let now = this.orders[i]; if (!now.cancel) { outputStr = '>' + now.date + ' ' + now.time + ' ' + now.price + '元'; } else { outputStr = '>' + now.date + ' ' + now.time + ' 违约金 ' + now.price + '元'; } console.log(outputStr); } console.log('> 小计:' + this.total + '元'); } } //订单类,包含订单的用户id、日期、时间、收入以及是否取消等信息 class Order { constructor(id, date, time, price) { this.id = id; this.date = date; this.time = time; this.cancel = false; this.price = price; } } //时间段判断函数 function countTimeSlice(start, end) { let timeLong = end - start, long1 = 0, long2 = 0, long3 = 0, long4 = 0; if (end <= 12) { long1 = timeLong; } else if (end <= 18) { if (start >= 12) { long2 = timeLong; } else { long1 = 12 - start; long2 = end - 12; } } else if (end <= 20) { if (start >= 18) { long3 = timeLong; } else if (start <= 12) { long2 = 18 - start; long3 = end - 18; } else { long1 = 12 - start; long2 = 6; long3 = end - 18; } } else { if (start >= 20) { long4 = timeLong; } else if (start >= 18) { long3 = 20 - start; long4 = end - 20; } else if (start >= 12) { long2 = 18 - start; long3 = 2; long4 = end - 20; } else { long1 = 12 - start; long2 = 6; long3 = 2; long4 = end - 20; } } return [long1, long2, long3, long4]; } //打印前对所有订单排序时调用的比较函数 function compareFn(a, b) { //先按日期排序再按时间排序 let dateA = new Date(a.date).getTime(); let dateB = new Date(b.date).getTime(); if (dateA !== dateB) { //以起始时间排序 let timeA = a.time.split('~'), startA = Number(timeA[0].split(":")[0]), timeB = b.time.split('~'), startB = Number(timeB[0].split(":")[0]); return startA - startB; } else { return dateA - dateB; } } let obj = new Program(); //监听输入并启动程序 let readline = require('readline'), read = readline.createInterface({ input: process.stdin, output: process.stdout }); read.on('line', obj.start.bind(obj)); })();
点赞
回复
分享
发布于 2017-09-12 17:11
努力给自己一个offer
华南理工大学 前端工程师
前端的,昨天已经交了,不知道其他岗位一不一样
点赞
回复
分享
发布于 2017-09-11 11:42
牛客1100750号
西北工业大学
大佬分享下
点赞
回复
分享
发布于 2017-09-11 09:38
一只小脑腐
한국외국어대학교 Java
求分享😂
点赞
回复
分享
发布于 2017-09-11 09:10
蓝色水晶
楼主
西安电子科技大学
恩恩,能不能给我指导一下
点赞
回复
分享
发布于 2017-09-11 09:07
pasky
中国科学院大学 Java
是羽毛球馆的么 刚提交。。。
点赞
回复
分享
发布于 2017-09-11 08:30
暂无评论,快来抢首评~
相关推荐
02-02 16:07
北京工业大学 Java
java业务项目选择求助
请问各位佬,星球上xfg的“拼团项目”适合跟着学么?需要先学一遍“小型支付商城”么?学习时长大概要多久呢?因为我看xfg项目大多是DDD架构的,感觉和MVC有些出入,不知道是跟着xfg写一个,还是再找一个MVC的学习了。求求大佬赐教赐教孩子吧
点赞
评论
收藏
分享
02-03 00:11
渤海大学 后端工程师
都 AI 写代码了,咋还问八股呢?
不知你是否是这样,习惯按TapTap补全代码;偶尔遇到个线程问题,忘记了语法,就直接对话框问AI;甚至在新项目初始化的时候,直接全部交给AI。AI Coding已经融了大部分的开发生活,使用已经是一种习惯。但即使你面试的AI Agent岗位,面试官还是会照例问你八股,这还有必要吗?我已经tap链接大脑,AI 代替思考了呀? AI 现状 很多产出变得更像“对的”,但更难确认它真的“能上线” 传统工作模式下,我们编码的工作受限于思考,心流的过程。但如果测试时发现问题,可以快速在脑海里定位到大概位置,心中有码。 而与AI人机协作后,我们更多的时间花在编码后的测试,因为代码没过脑,很多写法可能与现...
AI求职实录
点赞
评论
收藏
分享
02-05 20:34
蚌埠坦克学院 嵌入式软件开发
嵌入式开发可以干到多少岁
很多人问,嵌入式开发能干多久,其实没有固定上限。嵌入式更看能力和经验,而不是单纯年龄。年轻的时候,更多精力刷算法、调外设、熬夜加班;经验丰富后,更多靠设计架构、优化系统、指导新人。只要持续学习新技术、熟悉操作系统、掌握芯片和项目经验,完全可以干到 40+,甚至 50+ 也能在团队里发挥核心价值。嵌入式不像一些纯前端、前沿互联网岗位对体力或眼力要求那么高,更多是脑力活和经验活。坚持学习、跟上行业节奏,年龄从来不是限制。
程序员能干到多少岁?
点赞
评论
收藏
分享
评论
点赞成功,聊一聊 >
点赞
收藏
分享
评论
提到的真题
返回内容
全站热榜
更多
1
...
为什么说Java+langchain4j/spring AI依旧是传统后端
4077
2
...
字节飞书测开日常oc,附上面经
3139
3
...
腾讯AI产品一面:如何缓解幻觉?
2566
4
...
美团50亿收购叮咚买菜,校招HC会变多吗
2464
5
...
有了AI之后,程序员能不能干到65岁?
2105
6
...
测开前景
1987
7
...
腾讯提前批
1772
8
...
字节的offer流程需要多久
1747
9
...
文科生能做产品经理吗?
1747
10
...
莉莉丝前端一面
1511
创作者周榜
更多
正在热议
更多
#
在大厂上班是一种什么样的体验
#
12542次浏览
170人参与
#
你的mentor是什么样的人?
#
51188次浏览
723人参与
#
程序员找工作至少要刷多少题?
#
21401次浏览
275人参与
#
我和mentor的爱恨情仇
#
106317次浏览
950人参与
#
论秋招对个人心气的改变
#
13626次浏览
192人参与
#
机械人避雷的岗位/公司
#
44218次浏览
310人参与
#
为了减少AI幻觉,你注入过哪些设定?
#
6172次浏览
184人参与
#
秋招落幕,你是He or Be
#
54255次浏览
618人参与
#
校招第一份工作你干了多久?
#
136667次浏览
597人参与
#
高薪高压 vs 低薪wlb,你怎么选?
#
47423次浏览
291人参与
#
设计人如何选offer
#
189739次浏览
868人参与
#
考公VS就业,你怎么选?
#
91997次浏览
507人参与
#
职场上哪些行为很加分?
#
322621次浏览
3603人参与
#
你的秋招进行到哪一步了
#
2531140次浏览
23253人参与
#
牛客AI体验站
#
7872次浏览
212人参与
#
机械人还在等华为开奖吗?
#
312144次浏览
1582人参与
#
秋招投递记录
#
380969次浏览
3204人参与
#
12306一秒售罄,你抢到回家的票了吗?
#
2336次浏览
52人参与
#
我现在比当时_,你想录用我吗
#
9507次浏览
129人参与
#
重来一次,我还会选择这个专业吗
#
411329次浏览
3898人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务