CSES - Datatähti 2016 alku - Results
Submission details
Task:Osajono
Sender:tomivah
Submission time:2015-10-01 18:08:17 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:8:44: error: 'strlen' was not declared in this scope
  unsigned long long length = strlen( input );
                                            ^
input/code.cpp:18:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for ( int i = 0; i < length; ++i )
                     ^

Code

#include <iostream>
#include <string>

int main()
{
	char* input = new char[ 100001 ];
	std::cin.getline( input, 100001, '\n' );
	unsigned long long length = strlen( input );

	unsigned long long output = 0;
	unsigned long long characterCounts[ 26 ];

	for ( int i = 0; i < 26; ++i )
	{
		characterCounts[i] = 0;
	}

	for ( int i = 0; i < length; ++i )
	{
		characterCounts[ input[ i ] - 'A' ]++;
	}

	for ( int i = 0; i < 26; ++i )
	{
		int count = characterCounts[ i ];
		output += ( count * (count + 1) ) / 2;
	}

	std::cout << output << "\n";

	delete[] input;
	return 0;
}