华为笔试题 20200812
相比其他公司,确实简单,不需要太多技巧,基本功扎实就好。
第一题:模拟就好,每来一个顾客能找钱就找,20块优先用10块去找。
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int count[] = {0, 0, 0};
int num = 0;
int n = 0;
bool success = true;
while (cin >> num) {
n++;
if (num == 5) {
count[0]++;
} else if (num == 10) {
if (!count[0]) {
success = false;
break;
}
count[1]++;
count[0]--;
} else {
if (!count[0]) {
success = false;
break;
}
if (count[1]) {
count[0]--, count[1]--;
} else {
if (count[0] < 3) {
success = false;
break;
} else {
count[0] -= 3;
}
}
}
getchar();
}
if (success)
printf("true,%d", n);
else
printf("false,%d", n);
return 0;
} #include <cstdio>
#include <iostream>
using namespace std;
int matrix[110][110];
int s, m, n;
void dfs(int i, int j) {
if (i >= m || j >= n) return;
if (matrix[i][j] == 2) return;
matrix[i][j] = 2;
if (j < n - s && matrix[i][j + s]) {
dfs(i, j + s);
}
if (i < m - s && matrix[i + s][j]) {
dfs(i + s, j);
}
if (j >= s && matrix[i][j - s]) {
dfs(i, j - s);
}
if (i >= s && matrix[i - s][j]) {
dfs(i - s, j);
}
}
int main() {
// freopen("input.txt", "r", stdin);
cin >> s >> m >> n;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
cin >> matrix[i][j];
}
}
dfs(0, 0);
cout << (matrix[m - 1][n - 1] == 2) << endl;
return 0;
} #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
string str;
char c;
while (cin >> c) {
if (c == ',') break;
str += c;
}
cin >> n;
// cout << str << n;
vector<string> ss(n);
int flag = 1;
int l = 0, r = n - 1;
int i = 0;
while (i < str.length()) {
if (l == r) {
ss[l] += str[i++];
l--, r++;
flag = 0;
continue;
}
if (l == 0) {
flag = 1;
}
if (flag) {
ss[l++] += str[i++];
if (i == str.length()) break;
ss[r--] += str[i++];
continue;
}
if (!flag) {
ss[l--] += str[i++];
if (i == str.length()) break;
ss[r++] += str[i++];
}
}
string res;
for (int i = 0; i < n; i++) res += ss[i];
cout << res << endl;
return 0;
}
360集团公司福利 432人发布
查看1道真题和解析

