Skip to content

Instantly share code, notes, and snippets.

@kunishi
Created July 2, 2012 07:15
Show Gist options
  • Save kunishi/3031637 to your computer and use it in GitHub Desktop.
Save kunishi/3031637 to your computer and use it in GitHub Desktop.
ACM International Collegiate Programming Contest, Japan Domestic, 2006, Problem E
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *in;
char stack[100];
char str[100];
int n;
int c;
int top;
int bottom;
int i;
if (argc != 2) {
fprintf(stderr, "usage: %s file\n", argv[0]);
exit(1);
}
if ((in = fopen(argv[1], "r")) == NULL) {
fprintf(stderr, "cannot open %s\n", argv[1]);
exit(1);
}
n = 0; top = 0; i = 0;
while ((c = fgetc(in)) != EOF) {
if (c >= '0' && c <= '9') {
n = n * 10 + c - '0';
continue;
}
if (c >= 'A' && c <= 'Z') {
if (n != 0) {
stack[top ++] = n;
}
str[i ++] = c;
continue;
}
if (c == '(') {
stack[top ++] = n;
continue;
}
if (c == ')') {
}
if (c == '\n') {
top = 0;
n = 0;
continue;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment