View Code of Problem 9

#include <stdio.h>
#include <malloc.h>
#include <string.h>
#define MAX 100000
//char q[5][20]={"Pleasant goat\n","Pretty goat\n","Athletic goat\n","Lazy goat\n","Slow goat\n"};
char q[5][]={"Pleasant","Pretty","Athletic","Lazy","Slow"};
char p[20], pp[20];
int a[10001][6];
int b[5]={5,8,10,15,20};
int main()
{
    int n, i, j, pos = 0, lll;
    int  sum = 0;
    //fgets(p,20,stdin);
    //while (p[0]<='9' && p[0]>='0')
    while(scanf("%d",&n)!=EOF)
    {
        //scanf("%d",&n);
        //fgets(p,20,stdin);
        //i = 0;
        //n=0;
        /*while (p[i]<='9' && p[i]>='0')
        {
            n = (p[i] - '0')+ n*10;
            i++;
        }*/
        for (i=0; i<n; i++)
        {
            //fgets(p,20,stdin);
            scanf("%s %s", p, pp);
            for (j=0; j<5; j++)
            {
                if (strcmp(q[j],p) == 0)
                {
                    a[pos][j]++;
                    a[pos][5]++;
                    break;
                }
            }
        }
        pos++;
        //fgets(p,20,stdin);
    }
    for (i=0; i<pos; i++)
    {
        if (a[i][5]>9&&a[i][2]>0)
            sum+=50;
        for (j=0; j<5; j++)
            sum += b[j] * a[i][j];
        printf("Case #%d: %d\n",(i+1),sum);
        sum = 0;
    }
    return (0);
}

/*
Main.c:6:6: error: array type has incomplete element type
 char q[5][]={"Pleasant","Pretty","Athletic","Lazy","Slow"};
      ^
Main.c: In function 'main':
Main.c:12:27: warning: unused variable 'lll' [-Wunused-variable]
     int n, i, j, pos = 0, lll;
                           ^
*/

Double click to view unformatted code.


Back to problem 9