T1:First ABC 2
模拟
代码实现
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
auto i = s.find("ABC");
if (i == string::npos) cout << -1 << '\n';
else cout << i+1 << '\n';
return 0;
}
T2:Prefix and Suffix
模拟
代码实现
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
string s, t;
cin >> s >> t;
int ans = 0;
if (!t.starts_with(s)) ans += 2;
if (!t.ends_with(s)) ans += 1;
cout << ans << '\n';
return 0;
}
T3:Festival
可以从后往前扫描,对于有烟花的日子,答案为 0
,否则答案为 ans[i+1]+1
代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<bool> f(n);
rep(i, m) {
int a;
cin >> a;
f[a-1] = true;
}
vector<int> ans(n);
for (int i = n-1; i >= 0; --i) {
if (f[i]) ans[i] = 0;
else ans[i] = ans[i+1]+1;
}
rep(i, n) cout << ans[i] << '\n';
return 0;
}