字节跳动笔试100-100-100-000
第一题:闹钟题
#include #include #include using namespace std; int main(){ int n; cin >> n; vector nums; int h,m; for(int i=0;i<n;i++){ cin >> h >> m; nums.push_back(h*60+m); } int x, t; cin >> x; cin >> h >> m; t = h*60+m; int res; for(int i=nums.size()-1;i>=0;i--){ if(nums[i]+x<=t){ res = nums[i]; break; } } cout << res/60 << " " << res%60 << endl; return 0; } /* 3 5 0 6 0 7 0 59 6 59 */
第二题:加密
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <iterator> using namespace std; int main() { int n, k; string s; cin >> n >> k; cin >> s; string ret(n, 0); int acc_sum = 0; for (int i = 0; i < n; ++i) { int v = s[i] - '0'; if (0 == i) ret[0] = v + '0'; else if (0 == v) ret[i] = acc_sum + '0'; else ret[i] = !acc_sum + '0'; acc_sum ^= ret[i] - '0'; if (i >= k-1) acc_sum ^= ret[i - k + 1] - '0'; } cout << ret << endl; return 0; }
第三题:发奖金
#include<iostream> #include<vector> #include<algorithm> using namespace std; int main(){ int n; cin >> n; vector<int> nums; int v; for(int i=0;i<n;i++){ cin >> v; nums.push_back(v); } vector<int> price(n, 100); for(int i=1;i<n;i++){ if(nums[i]>nums[i-1]){ price[i] = price[i-1] + 100; } } for(int i=n-2;i>=0;i--){ if(nums[i]>nums[i+1]){ price[i] = max(price[i], price[i+1] + 100); } } int res=0; for(auto p:price) res += p; cout << res << endl; return 0; } /* 4 3 9 2 7 */
第四题:真的不会,哭唧唧!!!
#字节跳动##笔试题目#