单词录入 原题
#include <iostream>
using namespace std;
int main() {
int n, c, t;
cin >> n >> c;
int ans = 0, last = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &t);
if (t - last > c) {
ans = 0;
}
ans++;
last = t;
}
cout << ans << endl;
return 0;
}
字符串删减 原题
#include <iostream>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
int res = 0, cnt = 0;
for (int i = 0; i < n; i ++ ) {
if (s[i] == 'x') {
cnt++;
if (cnt == 3) {
res++, cnt--;
}
} else {
cnt = 0;
}
}
cout << res << endl;
return 0;
}
另外一题 摩尔投票题