#include <stdio.h>
#include <stdlib.h>
#define STACK_MAX (100)

// prototype
void res();
void push(int w);
int pop();

// global
int st[STACK_MAX];
int pt = 0;
char str[10];
int cnt[256] = {};

// process
int main()
{
  FILE *fp;
  int i;

  fp = fopen("c161-102.c.in", "r");
  printf("input = ");
  while ((fscanf(fp, "%s", str)) != EOF)
    res();
  printf("\nresult = %d\n", pop());
  for ( i = 0; i < 256; ++i)
    if (cnt[i])
      printf("%c %d\n", i, cnt[i]);

  return 0;
}


void res()
{
  int a, b;
  char c;

  printf("%s ", str);
  c = str[0];

  switch (c) {
  case '+':
    cnt[c]++;
    a = pop();
    b = pop();
    push(b + a);
    break;
  case '-':
    cnt[c]++;
    a = pop();
    b = pop();
    push(b - a);
    break;
  case '*':
    cnt[c]++;
    a = pop();
    b = pop();
    push(b * a);
    break;
  case '/':
    cnt[c]++;
    a = pop();
    b = pop();
    if (a == 0)
      break;
    push(b / a);
    break;
  default:
    push(atoi(str ));
    break;
  }
}

void push(int w)
{
  st[pt++] = w;
}

int pop()
{
  return st[--pt];
}
