123
返回列表 发新帖
楼主: gavin5566
跳转到指定楼层
上一主题 下一主题
收起左侧

twitter oa 一問

🔗
skysbjdy 2016-10-27 08:03:03 | 只看该作者
全局:
gavin5566 发表于 2016-10-26 14:42
本題

判斷ipv4 or ipv6

能再解释一下 ipv6这题 具体是什么啊??
回复

使用道具 举报

🔗
skysbjdy 2016-10-27 08:05:14 | 只看该作者
全局:

array里面的元素 有没有说全是正数??   还是正负 都有可能??  leetcode有个类似的 是求最短subarray sum >= k正好跟这个相反, 但是限制了array里面的数全是正数
回复

使用道具 举报

🔗
 楼主| gavin5566 2016-10-27 13:49:37 | 只看该作者
全局:
skysbjdy 发表于 2016-10-27 08:03
能再解释一下 ipv6这题 具体是什么啊??

判斷string 是ipv4 or ipv6
回复

使用道具 举报

🔗
raccoon 2016-10-29 15:06:45 | 只看该作者
全局:
也是遇到aggregation这题,也是一个case都不过,好怀疑人生,怀疑他们定的答案有问题。。。
回复

使用道具 举报

🔗
josh80214 2016-10-29 15:47:09 | 只看该作者
全局:
array a[], k 那道題有人做完了嗎? 我test case 9,10過不了
回复

使用道具 举报

🔗
EasonS 2016-10-30 10:02:27 | 只看该作者
全局:
# Enter your code here. Read input from STDIN. Print output to STDOUT
# need to check if in range
import sys
import collections

def validTimeRange (curTime, timeRange):
    minYear = int(timeRange[0][:4])
    minMonth = int(timeRange[0][-2:])
    maxYear = int(timeRange[1][:4])
    maxMonth = int(timeRange[1][-2:])
    curYear = int(curTime[:4])
    curMonth  = int(curTime[-2:])
    if (curYear < minYear or curYear > maxYear or
        (curYear == minYear and curMonth < minMonth) or
        (curYear == maxYear and curMonth >= maxMonth)):
        return False
    else:
        return True
   
   
def splitWithOptionalSpace (curLine, nextLine):
    engagement_index = 11
    if (nextLine[11] == ' '):
        engagement_index += 1
    engagement = ''
    while(nextLine[engagement_index] != ','):
        engagement += nextLine[engagement_index]
        engagement_index += 1
    curLine.append(engagement)
    count_index = engagement_index + 1
    if (nextLine[count_index] == ' '):
        count_index += 1
    count = ''
    while(nextLine[count_index] != '\n'):
        count += nextLine[count_index]
        count_index += 1
    curLine.append(count)
   
   
   
timeRange = sys.stdin.readline().split(', ')

sys.stdin.readline()

nextLine = sys.stdin.readline()
# string : {}
# {} is string : int
ret = {}
while (nextLine != ''):
    curLine = [nextLine[:10]]
    # deal with fields seperated by optional space
    splitWithOptionalSpace (curLine, nextLine)
    # test if time is in valid range
    curTime = curLine[0][:7]
    if (validTimeRange(curTime, timeRange) is False):
        nextLine = sys.stdin.readline()
        continue
    # aggregate one line to the structure we want
    if curTime not in ret:
        ret[curTime] = {curLine[1] : int(curLine[2])}
    else:
        if curLine[1] in ret[curTime]:
            ret[curTime][curLine[1]] += int(curLine[2])
        else:
            ret[curTime][curLine[1]] = int(curLine[2])
   
    nextLine = sys.stdin.readline()

# format output
for entry in sorted(ret.items(), key=lambda x: x[0], reverse=True):
    toPrint = entry[0] + ', '
    for subEntry in sorted(entry[1].items(), key=lambda x: x[0]):#, reverse=True):
        toPrint += subEntry[0] + ', ' + str(subEntry[1]) + ', '
    sys.stdout.write(toPrint[:-2] + '\n')
            

全过

评分

参与人数 1大米 +8 收起 理由
jigsaw_Becky + 8 感谢分享!

查看全部评分

回复

使用道具 举报

🔗
minniexu 2016-10-31 08:03:53 | 只看该作者
全局:
同问这道题,楼主解决了吗~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表