Monday, 11 January 2016

Solution of LIGHT OJ 1249 :: Chocolate Thief


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int tst, k;
    scanf("%d", &tst);
    for(k=1; k<=tst; k++)
    {
        int max = 0, min = 900000000, i, tst_2, l, w, h;
        scanf("%d", &tst_2);
        char name[tst_2][100];
        int ara[tst_2], loc_2, loc_1;
        for(i=0; i<tst_2; i++)
        {
            scanf("%s", name[i]);
            scanf("%d%d%d", &l, &w, &h);
            ara[i] = l*w*h;
            if(ara[i]<min)
            {
                min = ara[i];
                loc_1 = i;
            }
            if(ara[i]>max)
            {
                max = ara[i];
                loc_2 = i;
            }
        }
        if(min == max) printf("Case %d: no thief\n", k);
        else printf("Case %d: %s took chocolate from %s\n",k, name[loc_2], name[loc_1]);
    }
    return 0;
}

2 comments:

  1. why you use char name[tst_2][100] bt scanf("%s", name[i]). declare as a 2D array bt take input as a 1D array! how does it work!
    plz explain

    ReplyDelete

Note: only a member of this blog may post a comment.