字节跳动笔试
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;
} 