CSES - Datatähti 2016 alku - Results
Submission details
Task:Osajono
Sender:viderizer
Submission time:2015-09-29 18:17:33 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp:10:34: error: '::main' must return 'int'
 long main(long argc, char* argv[]) {
                                  ^
input/code.cpp:10:6: warning: first argument of 'int main(long int, char**)' should be 'int' [-Wmain]
 long main(long argc, char* argv[]) {
      ^

Code

#include <iostream>
#include <string>
#include <algorithm>
using std::cout;
using std::cin;
using std::string;
using std::count;
long main(long argc, char* argv[]) {
// take input
string input;
cin >> input;
// parse input
long chars[26] = {0}; // A -> 0, B -> 1 ... Z -> 25
for (int i = 0; i < 26; i++) {
chars[i] = count(input.begin(), input.end(), (char)(i+65));
}
// do the actual things
long sum = 0;
for (int i = 0; i < 26; i++) {
long p = 0;
if (chars[i] % 2 == 0) {
p = (chars[i] + 1) * (chars[i] / 2);
} else {
p = ((chars[i] + 1) * ((chars[i] - 1) / 2)) + ((chars[i] + 1) / 2);
}
sum += p;
}
// output
cout << sum << "\n";
return 0;
}