→ 题目已经补完了,来个复盘
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x;
int k;
cin >> x >> k;
int a[5] = {0};
for (int i = 4; i > 0; i--)
{
a[i] = x % 10;
a[i] %= k;
x /= 10;
}
int t = 0;
for (int i = 1; i <= 4; i++)
{
if (a[i] != 0)
{
t = i;
break;
}
}
// cout<<t<<'\n';
if (t == 0)
{
if (a[1] == 0)
cout << 0;
else
for (int i = 1; i <= 4; i++)
cout << a[i];
}
else
{
for (int i = t; i <= 4; i++)
cout << a[i];
}
return 0;
}
闰年
#include <bits/stdc++.h>
using namespace std;
int main()
{
int y;
cin >> y;
if (y % 4 != 0 || y % 100 == 0 && y % 400 != 0 || y % 3200 == 0 && y % 172800 != 0)
cout << "No";
if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0 && y % 3200 != 0 || y % 172800 == 0)
cout << "Yes";
return 0;
}
二进制
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
int n;
cin >> n;
while (n > 0)
{
cout << n / 2 << " " << n % 2 << '\n';
n /= 2;
}
return 0;
}
小S大战小Q
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int a[N], b[N];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
int s = 0, q = 0;
for (int i = 0; i < n; i++)
{
if (a[i] > b[i])
s++;
if (a[i] < b[i])
q++;
}
cout << s << " " << q << '\n';
if (s > q)
cout << "S";
else if (s < q)
cout << "Q";
else
cout << "Tie";
return 0;
}
放行李
复盘:这道题赛时没写出来,被喊去跑800了 ┭┮﹏┭┮ ,赛后仔细看了下题,发现当时自己大致看了一下,先想的是两个一维数组,但又改成了二维数组,重新思考了一下,应该是两个一维数组,分别代表这左边一列和右边一列,再暴力搜索每一列可以放的最小距离,进行判断,就 OK 了
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int l[N], r[N];
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> l[i];
for (int i = 1; i <= n; i++)
cin >> r[i];
int p, q;
cin >> p >> q;
int ans = 1e9, id = 0;
for (int i = 1; i <= n; i++)
{
if (l[i] == 0)
ans = min(ans, abs(i - q));
}
for (int i = 1; i <= n; i++)
{
if (r[i] == 0)
{
if (abs(i - q) < ans)
{
ans = abs(i - q);
id = 1;
}
}
}
if (ans == 1e9)
cout << -1;
else
cout << id << " " << ans;
return 0;
}
最大的和
复盘:这道题赛时也莫有写出,赛后补题它也是最后一道,主要瞟了一眼题目总感觉这道题写起来会很麻烦(我的畏难心理)。
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
int g[N][N];
void solve()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
cin >> g[i][j];
}
int ret = -1e9;
for (int i = 1; i <= n; i++)
{
int x = 0, y = 0;
for (int j = 1; j <= n; j++)
x += g[i][j], y += g[j][i];
ret = max({ret, x, y});
}
for (int i = 1; i <= n; i++)
{
int x = 0, y = 0;
for (int j = 0; i + j <= n; j++)
x += g[1 + j][i + j], y += g[i + j][1 + j];
ret = max({ret, x, y});
}
for (int i = n; i >= 1; i--)
{
int x = 0, y = 0;
for (int j = 0; i - j >= 1; j++)
x += g[1 + j][i - j];
for (int j = 0; i + j <= n; j++)
y += g[i + j][n - j];
ret = max({ret, x, y});
}
cout << ret << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
交题解
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin >> s;
for (int i = 0; i < s.size(); i++)
{
if (s[i] >= 'a' && s[i] <= 'z' || s[i] >= 'A' && s[i] <= 'Z')
cout << s[i];
}
return 0;
}
最好的交换
复盘:这道题在比赛时 WA 了,只拿了部分分,后面几个测试点 TLE。赛后重新去看这道题的时候,发现赛时不应该只想到交换就是直接交换数字,应该想的是交换数组里面对应的下标,这样才能 AC。
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int g[N][N], a[N], b[N]; // a 行 b 列
int main()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
cin >> g[i][j];
}
for (int i = 1; i <= n; i++)
a[i] = i, b[i] = i;
while (m--)
{
int op, x, y;
cin >> op >> x >> y;
if (x == y)
continue;
if (op == 1)
swap(a[x], a[y]);
else
swap(b[x], b[y]);
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
cout << g[a[i]][b[j]] << " ";
cout << '\n';
}
return 0;
}