USACO DEC06LEVEL1 Problem 'mgraph' Analysis

by Rob Kolstad

This solution requires nested loops -- one for reading the data and processing it; the other to print a number of '*'s on the line. Probably the only trick here is making sure you get exactly two digits of output for single-digit inputs:

#include <stdio.h>
main () {
    FILE *fin = fopen ("mgraph.in", "r");
    FILE *fout = fopen ("mgraph.out", "w");
    int n, i, j, size;
    fscanf (fin, "%d", &n);
    for (i = 0; i < n; i++) {
        fscanf (fin, "%d", &size);
        fprintf (fout, "%2d ", size);
        for (j = 0; j < size; j++)
            fputc ('*', fout);
        fputc ('\n', fout);
    }
    exit (0);
}