10.13 b站笔试
两个暴力题....
第一题,输出首尾交错后的数组
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
int a[N];
int tot = 1;
int main() {
while(cin >> a[tot]) {
char c = getchar();
if(c != ',') {
break;
}
++tot;
}
for(int left = 1, right = tot, i = 1; i <= tot ; i++) {
if(i&1) {
cout << a[left++];
} else {
cout << a[right--];
}
if(i != tot) {
cout << ",";
}
}
return 0;
} 第二题输出数组中每行都有的最小元素
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int a[N][N], n;
string s;
void ok() {
++n;
int now = 0;
int cnt = 0;
int len = s.size();
for(int i = 0; i < len; i++) {
if(s[i] == ',') {
a[n][++cnt] = now;
now = 0;
} else {
now = now * 10 + s[i] - '0';
}
}
a[n][++cnt] = now;
a[n][0] = cnt;
}
int main() {
while(cin >> s) {
ok();
}
int ans = 1e9;
for(int k = 1; k <= a[1][0]; k++) {
int cnt = 1;
for(int i = 2; i <= n; i++) {
for(int j = 1; j <= a[i][0]; j++) {
if(a[1][k] == a[i][j]) {
++cnt;
}
}
}
if(cnt == n) {
ans = min(ans, a[1][k]);
}
}
if(ans == (int)1e9) {
ans = -1;
}
cout << ans;
return 0;
} #B站##笔试题目##哔哩哔哩#
查看21道真题和解析
