- 字节笔试4/10
- 字节笔试3/20
- 81)4V.jpg![CL9VA06U05~UUJY6EY2IN6.jpg">![WR(3{IB57FC7L~$R281)4V.jpg![CL9VA06U05~UUJY6EY2IN6.jpg
">![TBXQQ(6PNGW@[JUVQ]8~8I9.jpg](/uploads/projects/pandazz@ugudkg/c20859d15b694c457622c1412a154619.jpeg)

字节笔试4/10
1






#include <iostream>using namespace std;int dx[4] = {-1, 0, 1, 0}, dy[4] = {0,-1, 0, 1}; //上左下右int main() {int t;cin >> t;while(t --){//输入int m, n;cin >> m >> n;int a[m][n];string row;//每一行用字符串读入,若用int读入,由于没有分隔符,会将一整行读入为一个数,如1011for(int i = 0; i < m; i ++){cin >> row;for(int j = 0; j < n; j ++){a[i][j] = row[j] - '0';}}/*101100000010可能存在先修改a[0][2]值为0,此时a[0][3]左下均为0,也要修改为0的问题前面的修改会影响后面的判断解决:不修改a[i][j]的值,直接输出0/1*/for(int i = 0; i < m; i ++){for(int j = 0; j < n; j ++){if(a[i][j] == 0) cout << 0;if(a[i][j] == 1){int cnt = 0;//遍历下左上右for(int k = 0; k < 4; k ++){int nx = i + dx[k], ny = j + dy[k];if(nx >= 0 && nx < m && ny >= 0 && ny < n && a[nx][ny] == 0) cnt ++;}if(cnt >= 2) cout << 0;else cout << 1;}}cout << endl;}}return 0;}
2





#include <iostream>#include <vector>using namespace std;int main() {int n;cin >> n;vector<int> energy(n, 0);for(int i = 0; i < n; i ++)cin >> energy[i];int most_r = 0;bool flag = true;for(int i = 0; i < n; i ++){if(i > most_r){flag = false;break;}most_r = max(most_r, i + energy[i]);}if(flag) cout << "TRUE";else cout << "FALSE";return 0;}
字节笔试3/20
1![(MKF15[_@P){GDE]4HF889H.jpg](/uploads/projects/pandazz@ugudkg/c7bbf7fa6c9f0a875ae5441a2e73de2c.jpeg)
#include <iostream>#include <unordered_map>using namespace std;int main() {string str;cin >> str;unordered_map<char, int> mp;bool ans = true;for (char& ch : str) {if (ch >= 'A' && ch <= 'Z')mp[ch + 32]++;else if (ch >= 'a' && ch <= 'z')mp[ch]++;elsemp['*']++;}bool flag = true;for (auto it = mp.begin(); it != mp.end(); it++) {int count = it->second;if (count % 2 == 0) continue;if (flag && count % 2 == 1) flag = false;else {ans = false;break;}}if (ans) cout << "true";else cout << "false";return 0;}
![WR(3{IB57FC7L~$R281)4V.jpg![CL9VA06U05~UUJY6EY2IN6.jpg
#include <iostream>
#include <vector>
using namespace std;
int main() {
int m, n;
cin >> m >> n;
vector<vector<int>> a(n, vector<int>(2));
for (int i = 0; i < n; i++) {
cin >> a[i][0] >> a[i][1];
}
int total = cost(m, a, n);
return
}
int cost(int m, vector<vector<int>>& a, int idx) {
if (idx == 0) return 0;
int totalprice = 0;
int minidx = idx + 1, minprice = INT_MAX;
for (int i = 0; i < idx; i++) {
if (a[i][1] < minprice) {
minidx = i;
minprice = a[i][1];
}
}
totalprice += (m - a[minidx][0]) * a[minidx][1] + cost(a[minidx][0], a, minidx);
return totalprice;
}
![2]_IU_9DCKY2T9`~{B93OP.jpg
4
