CSES - Datatähti 2017 alku - Results
Submission details
Task:Pakkaus
Sender:cattes
Submission time:2016-10-07 15:29:08 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp:52:2: error: stray '\366' in program
  int tröiger = 0;
  ^
input/code.cpp:64:4: error: stray '\366' in program
    if (tröiger == 1) {
    ^
input/code.cpp:77:5: error: stray '\366' in program
     tröiger = 0;
     ^
input/code.cpp:90:4: error: stray '\366' in program
    tröiger = 1;
    ^
input/code.cpp: In function 'char* notmain(char*)':
input/code.cpp:52:9: error: expected initializer before 'iger'
  int tröiger = 0;
         ^
input/code.cpp:64:8: error: 'tr' was not declared in this scope
    if (tröiger == 1) {
        ^
input/code.cpp:64:11: error: expected ')' before 'iger'
    if (tröiger == 1) {
           ^
input/code.cpp:77:8: error: expected ';' before 'iger'
     tröiger = 0;
        ^
input/code.cpp:90:4: error: 'tr' was not declared in this scope
    tröiger = 1;
    ^
input/code.cpp:90:7: error: expected ';' before 'iger'
    tröiger = 1;
       ^

Code

//#include <stdio.h>
#include <iostream>
#include <sstream>
#include <cstring>
#include <math.h>


int wut(char * asd) {
	if (asd == 0) { return 0; }
	int i = 0;
	while (1) {
		if (asd[i] != '\0') {
			i++;
		}
		else {
			break;
		}
	}
	return i;
}

void append(char ** dst, char * thing) {
	int a = wut(*dst);
	int b = wut(thing);
	char * lol = new char[a+b+1];
	lol[a + b] = '\0';
	memcpy(lol, *dst, a);
	memcpy(lol + a, thing, b);
	delete[] * dst;
	*dst = lol;
}

int shittyAtoi(char * input, int numNumbers) {
	int num = 0;
	for (int i = 0; i < numNumbers; i++) {
		if (i == numNumbers - 1) {
			num = num + (input[i] - 48);
		}
		else {
			num = num + (input[i] - 48) * pow(10,(numNumbers-i-1));
		}
	}
	return num;
}


char * notmain(char * input) {

	char * masterbuf = nullptr;

	int offset = 0;
	int tröiger = 0;

	char nums[20];
	int nn = 0;
	char letts[10000];
	int nl = 0;

	while (1) {
		char c = input[offset];
		

		if ((c <= 57 && c >= 48) || c == '\0') {
			if (tröiger == 1) {
				nums[nn] = '\0';
				letts[nl] = '\0';

				int num = shittyAtoi(nums, nn);
				for (int i = 0; i < num; i++) {
					append(&masterbuf, letts);
				}

				if (c == '\0') {
					break; 
				}

				tröiger = 0;
				nums[0] = c;
				nn = 1;
				nl = 0;
			}
			else {
				nums[nn] = c;
				nn++;
			}
		}
		else {
			letts[nl] = c;
			nl++;
			tröiger = 1;
		}

		offset++;
	}

	return masterbuf;

}

int main() {
	
	std::string input;
	std::cin >> input;
	std::cin.get();
	char * res = notmain((char *)(input.c_str()));

	std::cout << res;

	std::cin.get();
	return 0;
}