NC219654. SummerTrip
描述
Before he starts organizing the trip, Leo wants to know the total number of good itineraries that are possible given a calendar of events that will take place over the summer season.
输入描述
The input consists of one line with a string describing the sequence of event types in the summer season. All characters are lowercase English letters , with different letters represent different types of events. Character of the string encodes the -th event of the summer. There are no blanks or spaces in the string.The length of the input string is at least and at most characters.
输出描述
Print the number of good itineraries that exist for the given summer season.
示例1
输入:
abbcccddddeeeee
输出:
10
示例2
输入:
thenumberofgoodstringsis
输出:
143
C++(clang++11) 解法, 执行用时: 141ms, 内存消耗: 736K, 提交时间: 2021-03-29 20:11:31
#include<bits/stdc++.h> using namespace std; set<int>q[30]; string str; int ans; int main(){ cin>>str; for(int i=0;i<str.length();i++){ ans+=q[str[i]-'a'+1].size(); for(int j=1;j<=26;j++) q[j].insert(str[i]-'a'+1); q[str[i]-'a'+1].clear(); } cout<<ans<<endl; }