Page 1 of 1

277 - Cabinets

Posted: Thu Jun 13, 2002 7:39 pm
by Ivor
bzzz... I'm bored out of my scull trying to get this one accepted.

I'll just ask for the start, whether there is anything in the description stated not clearly enough?

And one more thing: does rejected record count as the 'first record of of the corresponding Style Code group'?

I appreciate any help available,
Ivor

Posted: Sun Jun 16, 2002 4:08 pm
by wyvmak
The test cases are weird,
i think the "first record" is the first one encounted in the group, even if it's rejected. and, the "first record" will only matter when the name is empty, i found that the name will be differed from the first record, but just use whatever name when there's one provided.

Posted: Sun Jun 16, 2002 7:54 pm
by Ivor
hmm... I don't think it got any clearer. :-?

Say I memorize the first name of the stylegroup. If it's empty -- I reject it. If I find another record with the same style code and no name, I look at the memorized name. Again -- if it's empty I reject it. Right? If not, then what's the problem?
i found that the name will be differed from the first record, but just use whatever name when there's one provided.
What did you mean? Did you mean that I should use the name of the first record that has a name? (and of course the same style code)

// puzzled
Ivor

Posted: Sun Jun 16, 2002 8:11 pm
by Adrian Kuegel
You memorize the first name of the stylegroup, even if it is empty. If there is another record with the same style code and no name, you have to reject it, because the memoized name is empty.

277 : Cabinets

Posted: Thu Jan 06, 2005 6:51 pm
by Guest
Hi,
I've got WA on this problem. I got a H-U-G-E data set from my friend and my program matches exactly with the correct output of that data set. I'm really confused with this problem. Someone please help me.. :(

Thanks in advance,

Code: Select all

#include<stdio.h>
#include<string.h>
#define MAX 200000

struct s{
	char code[5], name[20], desc[20], ext[30], price[10];
} cab[MAX];
int n;

int main(){
	//freopen("In.txt", "r", stdin);
	//freopen("Out.txt", "w", stdout);

	int i, j, t, len, price;
	char st[70], itemId[25], itemDesc[45];
	bool f = 1;
	gets(st);
	sscanf(st, "%d", &t);
	gets(st);
	while(t--){
		if(f) f= 0;
		else putchar(0xA);
		n = 0;
		while(gets(st) && st[0]){
			len = strlen(st);
			for(i=0; st[i]!=','; ++i) cab[n].code[i] = st[i]; cab[n].code[i] = 0;
			for(++i,j=0; st[i]!=','; ++i,++j) cab[n].name[j] = st[i]; cab[n].name[j] = 0;
			for(++i,j=0; i < len && st[i]!=','; ++i,++j) cab[n].desc[j] = st[i]; cab[n].desc[j] = 0;
			for(++i,j=0; i < len && st[i]!=','; ++i,++j) cab[n].ext[j] = st[i]; cab[n].ext[j] = 0;
			for(++i,j=0; i < len && st[i]!=','; ++i,++j) cab[n].price[j] = st[i]; cab[n++].price[j] = 0;
		}
		printf("Item Id,Item Desc,Item Price\n");
		for(i=0; i<n; ++i){
			sprintf(itemId, "%03s", cab[i].code);
			strcat(itemId, cab[i].desc);
			if(strlen(itemId) > 13) continue;
			if(!cab[i].name[0]){
				for(j=0; j<i && strcmp(cab[j].code, cab[i].code); ++j);
				if(j == i || !cab[j].name[0]) continue;
				strcpy(itemDesc, cab[j].name);
			}
			else strcpy(itemDesc, cab[i].name);
			if(cab[i].ext[0]){
				strcat(itemDesc, "-");
				strcat(itemDesc, cab[i].ext);
			}
			if(strlen(itemDesc) > 30) itemDesc[30] = 0;
			if(!cab[i].price[0]) price = 0;
			else sscanf(cab[i].price, "%d", &price);
			printf("%s,%s,%01d.%02d\n", itemId,itemDesc,price/100,price%100);
		}
	}
	return 0;
}