NC225352. Substring Characters
描述
输入描述
Input to your program is a series of lines terminated by end-of-file. Each line is a test case consisting of alphanumericcharacters (a–z, A–Z, 0–9). Upper-case and lower-case letters are distinct. The new line character is not part of thetest case string. No test case string will exceed characters. There will be at most test strings in input.
输出描述
For each input line print a line containing the number of proper minimal unique substrings of the input string with no leading or trailing whitespace and no extra leading signs or zeros.
示例1
输入:
aabbabb abAB34aB3ba7 104001144 aaabcaaa a bb bd 1234567
输出:
2 1 3 2 0 1 0 0
C++ 解法, 执行用时: 7ms, 内存消耗: 312K, 提交时间: 2021-08-14 12:33:05
#include<bits/stdc++.h> using namespace std; #define LL long long int main(){ string s; while(cin>>s){ set<string>q;q.clear(); set<char>p;p.clear(); map<char,int>o;o.clear(); for(int i=0;i<s.size();i++){ p.insert(s[i]); o[s[i]]++; } if(o[s[0]]==1&&o[s[s.size()-1]]==1){ cout<<0<<endl; continue; } int nm=p.size(),flag=0,res=-1,k=0; for(int i=0;i<s.size();i++){ set<char>v;v.clear(); map<char,int>oo;oo.clear(); string c=""; for(int j=i;j<s.size();j++){ c+=s[j]; oo[s[j]]++; v.insert(s[j]); if(v.size()==nm&&oo[s[i]]==1&&oo[s[j]]==1){ q.insert(c); break; } } } cout<<q.size()<<endl; } }