#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;
int cnt[256] = {0};
 
// process
int main()
{
  FILE *fp;
  int i;
  char buffer[1024];
  char *str;

  fp = fopen("c161-102.c.in", "r");
  while (str = fgets(buffer, sizeof(buffer), fp)) {
    printf("input  = %s", str);
    res(str);
	printf("result = %d\n", pop());
  }
  for ( i = 0; i < 256; ++i)
    if (cnt[i])
      printf("%c %d\n", i, cnt[i]);
 
  return 0;
}
 
 
void res(char *str)
{
  int a, b, i;
 
  for (i = 0;str[i] != '\0';i++){
      switch (str[i]) {
          case '+':
              a=pop();
              b=pop();
              push(b+a);
              break;
          case '-':
              a=pop();
              b=pop();
              push(b-a);
              break;
          case '*':
              a=pop();
              b=pop();
              push(b*a);
              break;
          case '/':
              a=pop();
              b=pop();
              if (a==0)
                  break;
              push(b/a);
              break;
          case ' ':
          case '\n':
			  break;
          default:
              push((int)str[i]-'0');
      }
  }
}
 
void push(int w)
{
  st[pt++] = w;
}
 
int pop()
{
  return st[--pt];
}
 