zoukankan      html  css  js  c++  java
  • 美团2020春招笔试

      经过连个小时的笔试考试真的发现自己的编码水平还是不行,感觉都是很简单的题,但是提交上去之后总是不能够AC,自己平时写代码也都是慢悠悠的写,没有注意过时间,经过这次的笔试,发现自己在规定的时间内写出一些没有bug代码,真的很难。

      像第一题,我知道该怎么写,但是写的时候思路很混乱,有些特殊的时间点也考虑不周全。结果提交了只通过了部分代码。感觉这次考试用到的数据结构的东西并不是太多,主要就是一些数学题。奈何自己大学不是数学专业的,也怪自己太菜了,平时也没有总结所学知识的习惯。感觉这次是没希望了,那么自己接下来应该选择什么样的路呢?

    ~~贴一下自己这两个小时写的代码吧,以后有时间在改正~~

    No 1.

    #include<iostream>
    #include<string>
    #include<cmath>
    #include<iomanip>
    
    using namespace std;
    
    int main() {
        int day, curMin;
        string time;
        cin >> day >> time >> curMin;
        int hh = stoi(time.substr(0, 2)) + 24 * (day - 1);
        int mm = stoi(time.substr(3, 2));
        int totalMin = hh * 60 + mm;
    
        int preMin;
        if (totalMin >= curMin) {
            preMin = totalMin - curMin;
            day = preMin / (24*60);
            hh = (preMin % (24*60)) / 60;
            mm = (preMin % (24*60)) % 60;
        } else {
            preMin = curMin - totalMin;
            day = 7 - (preMin / (24*60)) % 7;
            hh = 24 - (preMin % (24*60)) / 60;
            mm = 60 - (preMin % (24*60)) % 60;
        }
    
        cout << day << endl;
        cout << setfill('0');
        cout << setw(2) << hh << ":" << setw(2) << mm << endl;
    
        return 0;
    }

    刚才又看了一些代码,发现自己真的犯了一个很低级的错误,写变量的时候竟然写错了。现在在提交应该就能通过了。

    No 2.

    #include<iostream>
    #include<map>
    #include<vector>
    
    using namespace std;
    
    int main() {
        int n;
        cin >> n;
    
        map<int, int> start;
        map<int, int> end;
        vector<int> v;
    
        int temp;
        for (int i = 1; i <= n; ++i) {
            cin >> temp;
            start[temp] = i;
            v.push_back(temp);
        }
        for (int i = 1; i <= n; ++i) {
            cin >> temp;
            end[temp] = i;
        }
    
        int ans = 0;
        int s, e;
        for (int i = 0; i < n; ++i) {
            if (end[v[i]] < start[v[i]])
                ans++;
            else {
                for (int j = 0; j < i; ++j) {
                    if (end[v[i]] < end[v[j]]) {
                        ans++;
                        break;
                    }
                }
            }
        }
    
        cout << ans << endl;
    
        return 0;
    }

    No 3.

    #include<iostream>
    #include<cmath>
    
    using namespace std;
    
    int main() {
        int n, k;
        cin >> n >> k;
        int t = 1;
        while (1) {
            int temp = n / pow(k, t-1);
            if (temp == 0) break;
            t++;
        }
        t--;
    
        double d = 1 / k;
        int x = (t * (1 - d)) / (1 - pow(d, t));
    
        cout << x << endl;
    
    
        return 0;
    }

    No 4.

    #include<iostream>
    
    using namespace std;
    
    int main() {
        int n;
        cin >> n;
    
        int ans = 3;
    
        for (int i = 3; i < n; ++i) {
            ans = (ans * 3) % 1000000007;
        }
        
        ans = (ans * 2) % 1000000007;
    
        cout << ans << endl;
    
        return 0;
    }

    No 5.

    #include<iostream>
    #include<vector>
    #include<string>
    
    using namespace std;
    
    int main() {
        int n, k;
        cin >> n >> k;
    
        vector<string> v;
        vector<string> copy;
        string temp;
        for (int i = 0; i < k; ++i) {
            cin >> temp;
            v.push_back(temp);
        }
    
        copy = v;
    
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            cin >> temp;
            ans = 0;
            if (temp[0] == '?') {
                for (int j = 0; j < k; ++j) {
                    string str = temp.substr(1);
                    if (v[j] != "") {
                        while(str.find(v[j]) != string::npos) {
                            ans++;
                            int pos = str.find(v[j]);
                            str = str.substr(pos + v[j].length());
                        }
                    }
                }
                cout << ans << endl;
            } else if (temp[0] == '+') {
                int num = stoi(temp.substr(1)) - 1;
                if (v[num] == "") v[num] = copy[num];
                cout << "v[num] = " << v[num] << endl;
            } else if (temp[0] == '-') {
                int num = stoi(temp.substr(1)) - 1;
                v[num] = "";
            }
        }
    
        return 0;
    }

      通过这次笔试清楚了自己原来还是那么的菜,自己只会用C++写着一些代码还不够的,还要学习一些Java的知识,因为这些知识就算在笔试中没有考到,在面试中还是要考的。

    永远渴望,大智若愚(stay hungry, stay foolish)
  • 相关阅读:
    pipelinewise 学习二 创建一个简单的pipeline
    pipelinewise 学习一 docker方式安装
    Supercharging your ETL with Airflow and Singer
    ubuntu中使用 alien安装rpm包
    PipelineWise illustrates the power of Singer
    pipelinewise 基于singer 指南的的数据pipeline 工具
    关于singer elt 的几篇很不错的文章
    npkill 一个方便的npm 包清理工具
    kuma docker-compose 环境试用
    kuma 学习四 策略
  • 原文地址:https://www.cnblogs.com/h-hkai/p/12669717.html
Copyright © 2011-2022 走看看