返回题解分享
讨论 / 题解分享/ 帖子详情

子串简写(编程题) - 题解

#include <iostream>
#include <string>
using namespace std;

int main() {
    int k, cnt = 0;
    string s;
    char c1, c2;
    long long ans = 0;

    cin >> k >> s >> c1 >> c2;
    int n = s.size();

    for (int i = n - k, j = n - 1; i >= 0; i--, j--) {
        if (s[j] == c2) cnt++;
        if (s[i] == c1) ans += cnt;
    }

    cout << ans << endl;
    return 0;
}
0 回复 0 转发 1 喜欢 4 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!