TopcoderArchiveVisit Topcoder
SRM29 Jan 2015
SRM 654

SquareScoresDiv2

Problem statement, definition, constraints, and public examples.

Problem Statement

A substring of a string is a contiguous sequence of characters from the string. For example, each of the strings "ab", "bcd", and "e" is a substring of "abcde". On the other hand, "cba", "ace", and "f" are not substrings of "abcde".

The score of a string S is the number of ways in which we can select a non-empty substring of S such that all characters in the substring are the same. If two substrings consist of the same letters but occur at different places in S, they are still considered different. For example, the score of "aaaba" is 8: there are four occurrences of the substring "a", two occurrences of "aa", one occurrence of "aaa", and one of "b".

On her birthday, Maki got a String s from her friend Niko as a present. Calculate and return its score.

Definition

Class:
SquareScoresDiv2
Method:
getscore
Parameters:
String
Returns:
int
Method signature:
int getscore(String s)
(be sure your method is public)

Constraints

  • The length of s will be between 1 and 100, inclusive.
  • Each character in s will be a lowercase letter ('a'-'z').

Examples

  1. "aaaba"
    Returns: 8
    The example explained above.
  2. "zzzxxzz"
    Returns: 12
  3. "abcdefghijklmnopqrstuvwxyz"
    Returns: 26
  4. "p"
    Returns: 1
  5. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    Returns: 5050
    All substrings satisfy the condition.
Back to all problems