CSES - Datatähti 2016 alku - Results
Submission details
Task:Osajono
Sender:while(false)
Submission time:2015-09-29 13:37:58 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp:11:13: error: empty character constant
   char in = '';
             ^
input/code.cpp:6:1: error: expected ',' or ';' before 'bool'
 bool hasValidData = true;
 ^
input/code.cpp: In function 'int main()':
input/code.cpp:10:9: error: 'hasValidData' was not declared in this scope
  while (hasValidData) {
         ^

Code

#include <iostream>

using namespace std;

int chars[27] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
bool hasValidData = true;
int output=0;

int main() {
	while (hasValidData) {
		char in = '';
		cin >> in;
		int i = (int)i - (int)'A';
		if (i <= 27 && i >= 0) {
			chars[i]++;
		}
		else {
			hasValidData = false;
		}
	}
	for (int k = 0; k <= 27; k++)
	{
		int A = chars[k];
		if ((A / 2) * 2 == A) {
			output += (A + 1)*(A / 2);
		}
		else {
			output += A*((A / 2) + 1);
		}
	}
	cout << output;
	return 0;
}