柠檬微趣2.26笔试题

第一题IP地址拆分转16进制  CPP不太熟,写的很丑
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>

using namespace std;

void print(int num) {
    int i, j;
    i = num % 16;
    j = num / 16;
    if (j >= 10) {
        char res;
        res = j - 10 + 'A';
        cout << res;
    }
    else
        cout << j;
    if (i >= 10) {
        char res;
        res = i - 10 + 'A';
        cout << res;
    }
    else
        cout << i;
}

int main() {
    string ip_l;
    
    cin >> ip_l;
    string tmp;
    vector<int> res_a;
    for (auto c : ip_l) {
        if (c != '.')
            tmp += c;
        else {
            stringstream ss;
            int res;
            ss << tmp;
            ss >> res;
            if (res > 255 || res < 0) {
                cout << "X" << endl;
                return 0;
            }
            res_a.push_back(res);
            tmp.clear();
        }
    }
    int res;
    stringstream ss;
    tmp = "";
    for (int i = ip_l.rfind('.') + 1; i < ip_l.length(); ++i) {
        tmp += ip_l[i];
    }
    ss << tmp;
    ss >> res;
    if (res > 255 || res < 0) {
        cout << "X" << endl;
        return 0;
    }
    res_a.push_back(res);
    for (auto i : res_a) {
        print(i);
    }
    cout << endl;
    
    return 0;
}


第二题输出两点之间的最大角度,双指针只过了60
from collections import defaultdict

if __name__ == '__main__':
    hash_table = {}
    flag = 0
    data = list(map(float, input().split()))[1:]
    j = data.index(max([i for i in data if i - data[0] <= 180]))
    i = 0
    t = j
    res = data[j] - data[i]
    while(i != j and t != len(data)-1):
        i += 1
        t += 1
        if(data[j] - data[i] > res):
            res = data[j] - data[i]
    print(res)



    
第三题 上位中位数 AC
#include <iostream>
#include <climits>

using namespace std;

int main(int args, char *argv[]) {

    int N;
    cin >> N;
    int a[N], b[N];
    for(int i = 0; i < N; ++i)
        cin >> a[i];
    for(int i = 0; i < N; ++i)
        cin >> b[i];

    int m(0), n(0);
    while(m + n != N-1) {
        if(a[m] < b[n])
            ++m;
        else if(a[m] == b[n])
             ++m, ++n;
        else
            ++n;
    }
    if(b[n] < a[m])
        cout << b[n];
    else
        cout << a[m];
    
    return 0;
}
第四题,筛子点数,动态规划,ac
if __name__ == '__main__':
    n = int(input())
    dp = {
        1: {
            0: 1,
            1: 1,
            2: 2,
            3: 2
        }
    }
    for i in range(2, n+1):
        dic = {}
        keys = [i + j for i in dp[i-1] for j in dp[1]]
        dic = dic.fromkeys(keys, 0)
        for key_1 in dp[i-1]:
            for key_2 in dp[1]:
                dic[key_1 + key_2] += dp[i-1][key_1] * dp[1][key_2]
        dp[i] = dic
    for key in dp[n]:
        print("{}:{}".format(key, dp[n][key]))

第二题有人做出来吗,分享下思路


#柠檬微趣##笔试题目#
全部评论
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNext()) { int n = in.nextInt(); float[] nums = new float[n]; for(int i = 0;i<n;i++) nums[i] = in.nextFloat(); float res = 0; TreeSet<Float> set = new TreeSet<>(); set.add(nums[0]); for(int i = 1;i<n;i++) { float temp = nums[i] - 180; res = Math.max(res, nums[i] - set.ceiling(temp)); set.add(nums[i]); } System.out.println((float)Math.round(res*10)/10); } } }
点赞
送花
回复
分享
发布于 2020-02-26 21:14
第二题
点赞
送花
回复
分享
发布于 2020-02-26 21:14
滴滴
校招火热招聘中
官网直投
哪位大佬能帮忙贴一下第一题的程序?
点赞
送花
回复
分享
发布于 2020-02-26 22:27
直接就四道代码题呀?
点赞
送花
回复
分享
发布于 2020-03-03 20:03
一个3.12笔试的网友发来苦涩表情,这咋都不换题目呢?痛失真题库
点赞
送花
回复
分享
发布于 2020-03-12 21:08
我一月做的也是这题,他家题都不换吗
点赞
送花
回复
分享
发布于 2020-03-13 11:33
楼主能说下题目是什么不,直接四个代码有点蒙啊
点赞
送花
回复
分享
发布于 2020-03-13 22:21

相关推荐

2 23 评论
分享
牛客网
牛客企业服务