277 - Cabinets

All about problems in Volume 2. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
Ivor
Experienced poster
Posts: 150
Joined: Wed Dec 26, 2001 2:00 am
Location: Tallinn, Estonia

277 - Cabinets

Post 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

wyvmak
Experienced poster
Posts: 110
Joined: Thu Dec 13, 2001 2:00 am

Post 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.

Ivor
Experienced poster
Posts: 150
Joined: Wed Dec 26, 2001 2:00 am
Location: Tallinn, Estonia

Post 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

Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post 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.

Guest
New poster
Posts: 39
Joined: Wed May 19, 2004 5:52 pm
Location: Dhaka, Bangladesh
Contact:

277 : Cabinets

Post 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;
}

Post Reply

Return to “Volume 2 (200-299)”