3 条题解
-
4
没人写?那我来咯··
#include <iostream> #include <vector> using namespace std; vector<int> calculateStability(const string& s) { vector<int> stability(s.length()); for (int i = 0; i < s.length(); i++) { if (i+1 < s.length() && s[i] == s[i+1]) { stability[i] = 1 + (i > 0 ? stability[i-1] : 0); } else { stability[i] = (i > 0 ? stability[i-1] : 0); } } return stability; } int main() { string s; cin >> s; int m; cin >> m; vector<int> stability = calculateStability(s); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; int result = (a > 1 ? stability[b-2] - stability[a-2] : stability[b-2]); cout << result << endl; } return 0; }
- 1
信息
- ID
- 1934
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- (无)
- 递交数
- 875
- 已通过
- 82
- 上传者