字节跳动笔试

80 100 100 0 最后一题思路想岔了 最后时间不够了
1
#include <bits/stdc++.h>
using namespace std;

struct nz
{
    int h, m;
    nz(int h, int m) : h(h), m(m) {}
    nz add(int addm)
    {
        nz t(0, 0);
        t.m = m + addm;
        if (t.m / 60 > 0)
        {
            t.h = h + t.m / 60;
            if (t.h >= 24)
            {
                t.h -= 24;
            }
            t.m = t.m % 60;
        }
        else
        {
            t.h = h;
        }
        return t;
    }
    bool operator<(nz &c)
    {
        if (this->h != c.h)
            return this->h < c.h;
        else
            return this->m < c.m;
    }
    bool operator>(nz &c)
    {
        if (this->h != c.h)
            return this->h > c.h;
        else
            return this->m > c.m;
    }
};

int main()
{
    int n;
    cin >> n;
    vector<nz> clocks;
    for (int i = 0; i < n; i++)
    {
        int h, m;
        cin >> h >> m;
        clocks.push_back(nz(h, m));
    }
    sort(clocks.begin(), clocks.end());
    // for(auto c:clocks){
    //     cout<<"time: "<<c.h<<" "<<c.m<<endl;
    // }
    int x;
    cin >> x;
    int h, m;
    cin >> h >> m;
    nz tfinal(h, m);
    for (auto it = clocks.rbegin(); it != clocks.rend(); it++)
    {
        nz temp = (*it).add(x);
        // cout << temp.h << " " << temp.m << endl;
        if (temp > tfinal)
            continue;
        else //temp <= tfinal
        {
            cout << it->h << " " << it->m << endl;
            break;
        }
    }
    return 0;
}
2
#include <bits/stdc++.h>
using namespace std;

char yihuo(char c1, char c2)
{
    if ((c1 == '1' && c2 == '1') || (c1 == '0' && c2 == '0'))
        return '0';
    else
        return '1';
}

int main()
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    string res(n, ' ');
    char temp;
    res[n - 1] = s[n - 1 + k - 1];
    for (int i = n - 2; i >= n - k; i--)
    {
        res[i] = yihuo(s[i + k - 1], s[i + k]);
    }

    for (int i = n - k - 1; i >= 0; i--)
    {
        res[i] = yihuo(s[i + k - 1], yihuo(s[i + k], res[i + k]));
    }
    cout << res << endl;
    return 0;
}
3
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int maxlevel = -n, minlevel = n;
    vector<int> ys;
    for (int i = 0; i < n; i++)
    {
        int y;
        cin >> y;
        ys.push_back(y);
    }
    vector<int> m(n, 0);
    for (int i = 0; i < n - 1; i++)
    {
        if (ys[i] < ys[i + 1])
        {
            if (m[i] == 0)
            {
                m[i] = 100;
                m[i + 1] = 200;
            }
            else
            {
                m[i + 1] = m[i] + 100;
            }
        }
    }
    for (int i = n - 1; i >= 1; i--)
    {
        if (ys[i] < ys[i - 1])
        {
            if (m[i] == 0)
            {
                m[i] = 100;
                if (m[i - 1] < 200)
                    m[i - 1] = 200;
            }
            else
            {
                if (m[i - 1] < m[i] + 100)
                    m[i - 1] = m[i] + 100;
            }
        }
    }
    int sum = 0;
    for (auto c : m)
    {
        sum += ((c == 0) ? 100 : c);
    }
    cout << sum << endl;
    return 0;
}



#字节跳动##笔试题目#
全部评论
#include<iostream> #include<vector> #include<algorithm> using namespace std; typedef long long LL;    // 闹钟响==起床 typedef pair<int, int> PII; const int N = 110; int n, nedt; vector<PII> clk, last;    //时,分 int main() {     cin >> n;     int num = 0;     while(n--)     {         int h, m; cin >> h >> m;         clk.push_back({h, m});         int t = h * 60 + m;          last.push_back({t, num});         num++;     }     cin >> nedt;    //需要的分钟     int h, m; cin >> h >> m; //上课时间     int endtime = h * 60 + m;      sort(last.begin(), last.end());//按第一个排序      int l = 0, r = 0;     for(int i = last.size() - 1; i >= 0; i--) //从大到小     {         int tmp = last[i].first;                  if( tmp + nedt <= endtime)         {             l = last[i].first, r = last[i].second;             break;         }     }     cout << clk[r].first << ' ' << clk[r].second;     return 0; } 我第一题只有40行。。
点赞 回复
分享
发布于 2019-08-11 21:21
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(int argc,char* argv[]) {     int n;     int mins;     int h,m;     scanf("%d", &n);     vector<int> times;     times.clear();     for (int i = 0; i < n; ++i) {         scanf("%d%d",&h,&m);         times.push_back(h * 60 + m);     }     scanf("%d", &mins);     scanf("%d%d",&h,&m);     /* 计算最近时间 */     int nTime = 60 * h + m;     nTime -= mins;     if(nTime < 0) nTime += 24 * 60;     int minValue = 0x3f3f3f3f;     int mflag = 0;     for(int i = 0; i < times.size(); ++i) {         if(abs(times[i] - nTime) < minValue) {             minValue = abs(times[i] - nTime);             mflag = i;         }     }     printf("%d %d\n",times[mflag]/60, times[mflag]%60);     return 0; } 第一题算分钟就行了
点赞 回复
分享
发布于 2019-08-11 21:26
滴滴
校招火热招聘中
官网直投

相关推荐

点赞 4 评论
分享
牛客网
牛客企业服务