2020蓝桥杯省赛B组第二轮 H 字串分值

刷题真的有用,只要是做过了这个题就稳稳的啊

#include <iostream>
using namespace std;

typedef long long LL;

int last[200];

int main()
{
    string s;
    cin >> s;
    
    int n = s.size();
    s = ' ' + s;
    
    LL ans = 0;
    for (int i = 1; i <= n; i ++)
    {
        ans += (LL)(i - last[s[i]]) * (n - i + 1);
        last[s[i]] = i;
    }
    
    cout << ans << endl;
    return 0;
}

https://blog.csdn.net/weixin_46239370/article/details/115262482?utm_medium=distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-2.control&dist_request_id=&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-2.control

为了自己,和那些爱你的人
原文地址:https://www.cnblogs.com/zhmlzhml/p/14672097.html