蓝桥杯试题——子串分值
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int c[26]; //二十六个字母
string s;
int f(int m, int n)
{
int a = 0;
for (int i = m; i <= n; i++)
c[s[i] - 'a']++; //对应字母加加
for (int i = 0; i < 26; i++)
if (c[i] == 1) a++; //字母只出现过一次的a++
return a;
}
int main()
{
int answer = 0;
cin >> s;
int len = s.length();
for (int i = 0; i < len; i++)
for (int j = i; j < len; j++) {
answer += f(i, j);
memset(c, 0, sizeof(int) * 26); //重置零
}
cout << answer;
return 0;
}