A : 判断这个字符是不是yes的意思,直接转为大写或者小写判断即可
#include <bits/stdc++.h>
using namespace std;
signed main() {
int T;
cin >> T;
while (T--) {
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
s[i] = tolower(s[i]);
}
if (s == "yes") {
cout << "YES";
} else
cout << "NO";
cout << '\n';
}
return 0;
}
B :一次解决保底获得一个气球,所以总共保底获得n个气球,另外首次获得ans++,初始化一个bool 类型的数组存放是否首次解决。
#include <bits/stdc++.h>
using namespace std;
bool f[30];
signed main() {
int T;
cin >> T;
while (T--) {
for (int i = 0; i <= 26; i++) {
f[i] = false;
}
int n;
cin >> n;
string s;
cin >> s;
int ans = 0;
for (int i = 0; i < n; i++) {
if (!f[s[i] - 'A']) {
ans++;
}
f[s[i] - 'A'] = true;
}
printf("%d\n", ans + n);
}
return 0;
}
C : 纯模拟,既然给出的是最后密码锁上的数字,那么久对给出的操作反向计算,U就是减,D就是加,最后对每一步操作规定边界,不能超过9也不能为负数。
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int pas[N];
signed main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> pas[i];
}
for (int j = 0; j < n; j++) {
int op, opn = 0;
string x;
cin >> op >> x;
for (int i = 0; i < op; i++) {
if (x[i] == 'U') {
pas[j]--;
}
if (x[i] == 'D') {
pas[j]++;
}
if (pas[j] < 0) {
pas[j] += 10;
}
pas[j] %= 10;
}
}
for (int i = 0; i < n; i++) {
cout << pas[i] << ' ';
}
cout << '\n';
}
return 0;
}
D : 哟西,这道题之后好好看看STL。
想到了是要用map来解决,但是当时不会用,没看过这部分内容。知识储备量太少了 呜呜。
存放每个单词到map,然后我们枚举分割点,这样就生成了两个单词,然后查找这两个单词是否在map里面
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
bool v[N];
string s[N];
signed main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
memset(v, 0, n + 1);
map<string, bool> m;
for (int i = 1; i <= n; i++) {
cin >> s[i];
m[s[i]] = true;
}
for (int i = 1; i <= n; i++) {
int l = s[i].length();
for (int j = 0; j < l; j++) {
string x, y;
for (int k = 0; k < j; k++) {
x += s[i][k];
}
for (int k = j; k < l; k++) {
y += s[i][k];
}
if (m[x] && m[y]) {
v[i] = 1;
}
}
}
for (int i = 1; i <= n; i++) {
cout << v[i];
}
cout << '\n';
}
return 0;
}
E : 旋转这个矩阵之后,选择要不要改变这个位置,要么全变1要么全变0。计算下是边0步骤少还是1。
旋转 90 °,x 变为原本的y,y变为上一次的x-n+1
此后的旋转同理。
ans/4 或者枚举一半的矩阵,后者会快些。
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N][N];
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
s = " " + s;
for (int j = 1; j <= n; j++) {
a[i][j] = s[j] - '0';
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int sum = 0;
int nowi = i, oldi = i, nowj = j, oldj = j;
sum += a[nowi][nowj];
nowi = oldj;
nowj = n - oldi + 1;
oldi = nowi;
oldj = nowj;
sum += a[nowi][nowj];
nowi = oldj;
nowj = n - oldi + 1;
oldi = nowi;
oldj = nowj;
sum += a[nowi][nowj];
nowi = oldj;
nowj = n - oldi + 1;
oldi = nowi;
oldj = nowj;
sum += a[nowi][nowj];
ans += min(sum, 4 - sum);
}
}
cout << ans / 4 << '\n';
}
signed main() {
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}
F : 找到i , j 可以使
a[i] < i < a[j] < j
统计一下到 i 之前有多少个数字满足 a[i] < i 的,存放在 s[i] 里面。
在满足 a[j] < j 的情况下,如有配对,那么 i <= a[j]-1 ,而且i < j ,对于 i < a[j]-1 的情况都已经包含在 s[a[j]-1]里了,所以 ans += ;
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10;
int arr[N], v[N], s[N];
signed main() {
int T;
cin >> T;
while (T--) {
memset(s, 0, sizeof(s));
memset(v, 0, sizeof(v));
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
if (arr[i] < i) {
v[i] = 1;
}
s[i] = s[i - 1] + v[i];
}
int ans = 0;
for (int i = 1; i <= n; i++) {
if (v[i])
ans += s[arr[i] - 1];
}
cout << ans << '\n';
}
return 0;
}