Code Submission Evaluation System Login

Datatähti 2016 alku

Start:2015-09-28 00:00:00
End:2015-10-12 00:00:00
 

Tasks | Scoreboard | Statistics


CSES - Datatähti 2016 alku - Results
History
2015-09-30 23:53:430
2015-09-30 14:08:35100
2015-09-30 14:08:0239
2015-09-30 14:06:3639
2015-09-29 18:17:58100
2015-09-29 18:17:33
2015-09-29 18:05:5739
2015-09-29 17:57:470
2015-09-29 17:51:210
Task:Osajono
Sender:viderizer
Submission time:2015-09-29 18:17:33
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;
}