网易互娱-8.9-人工智能岗笔试题-Python

总结:仔细读题,细心...

1.个税缴纳

易错点:各个边界的数值,以及最后的四舍五入

def calTax(money):
    more = money - 5000
    if more <= 0:
        return 0
    if more < 3000:
        return more * 0.03
    if 3000 <= more < 12000:
        return 3000 * 0.03 + (more - 3000) * 0.1
    if 12000 <= more < 25000:
        return 3000 * 0.03 + 9000 * 0.1 + (more - 12000) * 0.2
    if 25000 <= more < 35000:
        return 3000 * 0.03 + 9000 * 0.1 + 13000 * 0.2 + (more - 25000) * 0.25
    if 35000 <= more < 55000:
        return 3000 * 0.03 + 9000 * 0.1 + 13000 * 0.2 + 10000 * 0.25 + (more - 35000) * 0.3
    if 55000 <= more < 80000:
        return 3000 * 0.03 + 9000 * 0.1 + 13000 * 0.2 + 10000 * 0.25 + 20000 * 0.3 + (more - 55000) * 0.35
    if more >= 80000:
        return 3000 * 0.03 + 9000 * 0.1 + 13000 * 0.2 + 10000 * 0.25 + 20000 * 0.3 + 25000 * 0.35 + (more - 80000) * 0.45

if __name__ == "__main__":
    T = int(input())
    # 四舍五入到整数
    for _ in range(T):
        money = int(input())
        print(int(calTax(money) + 0.5))

2.成员列表

dic1 = {}
N = int(input())  #群组人数-身份
for _ in range(N):
    line = input().split()
    identity, name = int(line[0]), line[1]
    dic1[name] = identity

dic2 = {}
M = int(input())  #成员状态变化记录-状态
for _ in range(M):
    line = input().split()
    name, status = line[0], int(line[1])
    dic2[name] = status

for name in dic2:
    dic1[name] += dic2[name] * 10

res = sorted(dic1.items(), key=lambda kv: (-kv[1], kv[0]))
for name, val in res:
    print(name)

3. 时间区间

测试用例过了,但是0%-AC,不知道哪里错了,求指正

def helper(w, time):
    h,m,s = list(map(int, time.split(":")))
    return w * 24 * 3600 + h * 3600 + m * 60 + s  # 转换成秒数

def judge(time, openday):
    res = float("inf")
    for begin, end in openday:
        if begin <= time <= end:
            return 0
        if begin > time:
            res = min(res, begin - time)
    return res

T = int(input())  # 样例数
for _ in range(T):
    openday = []
    K = int(input())  # K天开放
    for _ in range(K):
        line = input().split()
        W, M = int(line[0]), int(line[1])
        for i in range(M):
            begin, end = line[i+2].split("-")
            openday.append((helper(W, begin), helper(W, end)))

    c = int(input())  # c个查询
    for _ in range(c):
        line = input().split()
        w, clock = int(line[0]), line[1]
        time = helper(w, clock)
        print(judge(time, openday))
#网易##笔试题目##Python#
全部评论
至于第三题,有一种case是一周中只有当天才开放,然后查询的时间是当天开放时间之后,得查到7天后。 想出这个case之前我也是0的通过率,改了之后ac了
点赞 回复 分享
发布于 2018-08-12 17:27
有个问题想问楼主,第二题(就是im成员列表排序更新的那一道题),题目中说最初给出成员权限级别时,成员排序是按照字典序的,我看楼主的代码中没有考虑这个排序?
点赞 回复 分享
发布于 2018-08-12 17:22
其实你要考虑从有序数组中找不到下一个时刻的情况,因为周是循环的,这个边界case要考虑下。
点赞 回复 分享
发布于 2018-08-10 19:57
C++版 纳税题(通过率100%) #include #include using namespace std; int main(int argc, char* argv[]) { int T = 0; while(cin >> T) { for(int i=0;i<T;i++) { int N = 0; cin >> N; vector a = {0, 3000, 12000, 25000, 35000, 55000, 80000}; vector b = {0.03, 0.1, 0.2, 0.25, 0.3, 0.35, 0.45}; float sum = 0; int rest = N-5000; for(int i=0;i<b.size()-1;i++) { if(rest>a[i]) { sum += (rest>a[i+1]?(a[i+1]-a[i]):(rest-a[i])) * b[i]; } } if(rest>a[6]) { sum += (rest-a[6]) * b[6]; } sum += 0.5; cout << int(sum) << endl; } } return 0; 聊天会话列表题(通过率100%) #include <iostream> #include <string> #include <map> #include <vector> #include <algorithm> using namespace std; typedef struct Node { int id; string name; }Node; typedef struct compare { map<string, int> record; compare(map<string, int> record) { this->record = record; } bool operator () (Node a, Node b) { /* 状态不同 */ if(this->record[a.name]!=this->record[b.name]) { return this->record[a.name] > this->record[b.name]; } /* 身份不同 */ if(a.id!=b.id) { return a.id > b.id; } return a.name < b.name; } }compare; int main(int argc, char* argv[]) { int N = 0; while(cin >> N) { vector<Node> group; for(int i=0;i<N;i++) { int id = 0; string name; cin >> id >> name; group.push_back({id, name}); } int M = 0; cin >> M; map<string, int> record; for(int i=0;i<M;i++) { string name; int state; cin >> name >> state; record[name] = state; } compare cmp(record); stable_sort(group.begin(), group.end(), cmp); for(auto it:group) { cout << it.name << endl; } } return 0; } 时间区间题(通过率0%, 时间来不及,差一点了) #include <iostream> #include <vector> #include <map> using namespace std; typedef struct Node { int start; int end; }Node; int calc_time(map<int, vector<Node>>& schedule, int W, int& time, bool& flag) { int wait = 0; if(schedule.count(W)!=0) { for(auto it:schedule[W]) { if(time<it.start) { wait = it.start - time; flag = true; break; } if(time>=it.start && time<=it.end) { wait = 0; flag = true; break; } } if(!flag) { wait = 24 * 3600 - time; time = 0; } } else { wait = 24 * 3600 - time; time = 0; } return wait; } int main(int argc, char* argv[]) { int T = 0; while(cin >> T) { for(int i=0;i<T;i++) { int K = 0; cin >> K; map<int, vector<Node>> schedule; for(int j=0;j<K;j++) { int W = 0, M = 0; cin >> W >> M; for(int k=0;k<M;k++) { int HH, MM, SS; char ch; int start = 0, end = 0; cin >> HH >> ch >> MM >> ch >> SS; start = HH * 3600 + MM * 60 + SS; cin >> ch >> HH >> ch >> MM >> ch >> SS; end = HH * 3600 + MM * 60 + SS; schedule[W].push_back({start, end}); } } int C = 0; cin >> C; for(int j=0;j<C;j++) { int W = 0; int HH, MM, SS; char ch; cin >> W >> HH >> ch >> MM >> ch >> SS; int time = HH * 3600 + MM * 60 + SS; bool flag = false; int wait = calc_time(schedule, W, time, flag); while(!flag) { W++; wait += calc_time(schedule, W, time, flag); } cout << wait << endl; } } } return 0; }
点赞 回复 分享
发布于 2018-08-10 19:50
楼主,请问第二题,kv: (-kv[1], kv[0]) 这里的排序顺序不应该是反过来吗kv: (kv[0], -kv[1])?
点赞 回复 分享
发布于 2018-08-10 17:46
欢迎大家投递阿里巴巴的岗位: https://www.nowcoder.com/discuss/92048?type=7&order=0&pos=7&page=2
点赞 回复 分享
发布于 2018-08-10 01:49
你好,可以吧题目发一下吗
点赞 回复 分享
发布于 2018-08-10 01:02
最后一题没有考虑时间在下一周的情况吧
点赞 回复 分享
发布于 2018-08-10 00:29
我也做出来两个,请教下最后一题有啥思路啊
点赞 回复 分享
发布于 2018-08-10 00:02

相关推荐

不愿透露姓名的神秘牛友
07-15 17:17
听说过付费实习,没想到这么贵啊我去,要不我给你个腰子吧
哈哈哈,你是老六:这种公司一定要注意啊,不要随便签合同,只要签了后面钱可能回不来,而且你通过法律途径也弄不回
点赞 评论 收藏
分享
评论
点赞
31
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务