/*
 * 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 vstup[DELKA];
    double x, y;
    double complex cx,cy;
    while (scanf("%s", vstup) != EOF) {
        if (sscanf(vstup, "%lg,%lg", &x, &y) == 2) {
            push(x + y * I);
        } else if (sscanf(vstup, "%lgL%lg", &x, &y) == 2) {
            push( x*cos(y) + x*sin(y)*I );
        } else if (sscanf(vstup, ",%lg", &y) == 1) {
            push( y*I );
        } else if (sscanf(vstup, "%lg", &x) == 1) {
            push( x );
        } else if (strcmp(vstup, "+") == 0) {
            cx = pop();
            cy = pop();
            push(cx + cy);
            tiskni();
        } else if (strcmp(vstup, "print") == 0) {
            tiskni();
        } else if (strcmp(vstup, "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");
}





