/*
 * Soubor:  20110408-Fri-complex.c
 * Datum:   08.04.2011 08:22
 * Autor:   Marek Nožka, nozka <@t> spseol <d.t> cz
 * Licence: GNU/GPL 
 * Úloha: 
 * Popis:   
 */

#define _ISOC99_SOURCE
#define _GNU_SOURCE
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
#include <complex.h>
#include <string.h>

/* ***************    Makra    ******************** */
#define ZASPOC 32
#define DELKA 32

/* ***************   Funkce    ******************** */

void push(double complex number);
double complex pop(void);
void tiskni(void);
void etiskni(void);

/****************************************************
 *               Hlavní program.
 ****************************************************/
int main(void)
{
    char enter[DELKA];
    double x, y;
    while (scanf("%s", enter) != EOF) {
        if (sscanf(enter, "%lg,%lg", &x, &y) == 2) {
            push(x + y * I);
        } else if (sscanf(enter, "%lgL%lg", &x, &y) == 2) {
            push(x * cos(y) + I * x * sin(y));
        } else if (sscanf(enter, ",%lg", &y) == 1) {
            push(y * I);
        } else if (sscanf(enter, "%lg", &x) == 1) {
            push(x);
        } else if (strcmp(enter, "print") == 0) {
            tiskni();
        } else if (strcmp(enter, "eprint") == 0) {
            etiskni();
        }

    }

    return 0;
}

double complex zasobnik[ZASPOC];
int pocet = 0;

void push(double complex number)
{
    if (pocet < ZASPOC) {
        zasobnik[pocet] = number;
        pocet++;
    }
}

double complex pop(void)
{
    if (pocet > 0) {
        pocet--;
        return zasobnik[pocet];
    } else {
        return NAN;
    }
}

void tiskni(void)
{
    printf("[ ");
    for (int i = 0; i < pocet; i++) {
        printf("(%g", creal(zasobnik[i]));
        if (cimag(zasobnik[i]) >= 0) {
            putchar('+');
            printf("j%g) ", cimag(zasobnik[i]));
        } else {
            putchar('-');
            printf("j%g) ", -cimag(zasobnik[i]));
        }
    }
    printf("]\n");
}

void etiskni(void)
{
    printf("[ ");
    for (int i = 0; i < pocet; i++) {
        printf("(%gL%g) ", cabs(zasobnik[i]), carg(zasobnik[i]));
    }
    printf("]\n");
}

