fork download
  1. #include<iostream>
  2. #include<cmath>
  3. #include<algorithm>
  4. #include<iomanip>
  5. #include<climits>
  6. #include<numeric>
  7. #include<set>
  8. #include<sstream>
  9. #include<map>
  10. #include<vector>
  11. #include<string>
  12.  
  13. using namespace std;
  14.  
  15. vector<string> split(string haystack, string needle) {
  16. vector<string> result;
  17. int start_pos = 0;
  18. int found_pos = haystack.find(needle, start_pos);
  19. while (found_pos != string::npos) {
  20. int count = found_pos - start_pos;
  21. string token = haystack.substr(start_pos, count);
  22. if (!token.empty()) {
  23. result.push_back(token);
  24. }
  25. start_pos = found_pos + needle.length();
  26. found_pos = haystack.find(needle, start_pos);
  27. }
  28. string token = haystack.substr(start_pos, haystack.length()-start_pos);
  29. if (!token.empty()) {
  30. result.push_back(token);
  31. }
  32. return result;
  33. }
  34. string nameConvert(const string& name) {
  35. const string DELIMITER = " ";
  36. stringstream builder;
  37. auto parts = split(name, DELIMITER);
  38. for (auto part : parts) {
  39. part[0] = toupper(part[0]);
  40. transform(part.begin()+1, part.end(),part.begin()+1, ::tolower);
  41. builder << part << DELIMITER;
  42. }
  43. return builder.str();
  44. }
  45. string dateConvert(const string& date) {
  46. const string DELIMITER = "/";
  47. stringstream builder;
  48. auto parts = split(date, DELIMITER);
  49. builder << setw(2) << setfill('0') << parts[0] << DELIMITER;
  50. builder << setw(2) << setfill('0') << parts[1] << DELIMITER;
  51. builder << parts[2];
  52. return builder.str();
  53.  
  54. }
  55.  
  56. int main() {
  57. string s;cin >> s;
  58. map<char, int> mp;
  59. for (auto value : s) {
  60. mp[value]++;
  61. }
  62. long long result = 0;
  63. for (char c = 'a';c <= 'z';c++) {
  64. result = result + (1ll * (mp[c]) * (mp[c] + 1) / 2);
  65. }
  66.  
  67. cout << result;
  68. }
  69.  
  70.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty