598 - Bundling Newspapers

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

Moderator: Board moderators

guang_1225
New poster
Posts: 2
Joined: Tue Feb 19, 2008 7:49 pm

problem solved...

Post by guang_1225 » Thu Feb 21, 2008 8:42 am

This testcase:

Code: Select all

1

1                      9
1
2
3
4
5
6
7
8
9
10
The output should be:

Code: Select all

Size 1
              9
1
2
3
4
5
6
7
8
9
10


Schneider
New poster
Posts: 1
Joined: Sat Feb 23, 2008 7:36 pm

598: Bundling eccentric newspapers

Post by Schneider » Sat Feb 23, 2008 8:30 pm

CUHK made 598 an assignment problem and implemented their own online judge, which accepts some programmes UVa rejects and rejects some UVa accepts. Moreover, my friend Mr. Guang discovered that UVa takes the lines containing "*" or 1-2 numbers to be exactly 9 characters long (10 if passed through fgets) and anything after that, with or without a line-feed occurring, is considered the first newspaper title. He illustrated his finding in reply to his own post. Confirmation or evidence to the contrary is appreciated.

My code got accepted at last without compromising to the 9-char limit. Another issue: the online judge reported WA previously but all I did was printing one extra linefeed at the end.

windkit
New poster
Posts: 1
Joined: Tue Feb 26, 2008 11:21 am

Post by windkit » Tue Feb 26, 2008 11:23 am

Accepted in UVa
but

Limit Exceeded: Output Limit Exceeded

in CU judge= =

Imti
Learning poster
Posts: 53
Joined: Sat Dec 04, 2010 12:00 pm
Location: Bangladesh
Contact:

Re: 598: Bundling eccentric newspapers

Post by Imti » Sat Jan 29, 2011 12:53 pm

Thnx Jackie for his necessary post...
[cpp] scanf("%d", &n);
gets(tmp), gets(tmp);
for (NULL; n--; NULL)
{
gets(tmp);
c = sscanf(tmp, "%d%d", &a, &b);
t = 0;
for (NULL; gets(buf[t]) && buf[t][0]; ++t)
;
if (c == 0)
display(1, t);
else if (c == 1)
display(a, a);
else
display(a, b);
if (n)
printf("\n");
}[/cpp]
I was getting WA.Because I was doing

Code: Select all

scanf("%d",&n);
gets(tmp);
while(n--)
{
gets(tmp);
gets(tmp);
i=0;
while(gets(buf[i])&&buf[i])
   i++;
if(str[0]=='*')
{s=1;e=i;}
else if(str[1]=='\0')
{s=atol(tmp);e=s;}
else
{ssacnf(tmp,"%d%d",&s,&e);}
if(flag)
 printf("\n");
flag=1;
for(size=s;size<=e;size++)
{
display_output();
printf("\n");
}
}
But this code was giving me WA.When I transformed input parsing system to like jackie's code,i got acc.Plz can anyone make me understand how differs my approach from jackie's one?

ashleyjames222
New poster
Posts: 1
Joined: Fri Dec 16, 2011 9:26 am

Re: 598: Bundling eccentric newspapers

Post by ashleyjames222 » Fri Dec 16, 2011 9:38 am

you are not using this tag (NULL; n--; NULL)

magurmach
New poster
Posts: 26
Joined: Mon May 14, 2012 8:19 pm

Re: 598: Bundling eccentric newspapers

Post by magurmach » Sat Jun 23, 2012 10:44 pm

Getting WA in this problem. No idea why!
Code link:
Code removed after AC
Made silly mistakes
a b means show all subset sizes from a to b, inclusive
Tested nearly all cases available. Plz help.
Thanks in advance!

AhmadKhatar
New poster
Posts: 28
Joined: Fri Mar 30, 2012 12:57 am

Re: 598: Bundling eccentric newspapers

Post by AhmadKhatar » Fri Oct 12, 2012 9:58 pm

Hi!
I don't know why I get WA.
Does anybody know the bug?
Thanks in advance! :D
Here is my code:

Code: Select all

#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>

using namespace std;

int m;
string names [ 12 ];
int cnt;
char query [ 63 ];

void process();
void backtrack( int stInd, int rem, string output );

int main()
{
	char tLine [ 63 ];

	cin >> m;
	cin.ignore();
	cin.ignore();

	for ( int i = 0; i < m; i++ )
	{
		cnt = 0; // refresh

		cin.getline( query, 63, '\n' );

		cin.getline( tLine, 63, '\n' );
		while ( tLine[ 0 ] != NULL )
		{
			names[ cnt++ ] = tLine;
			cin.getline( tLine, 63, '\n' );
		}

		if ( i >= 1 )
		{
			cout << endl;
		}
		process();
	}

	return 0;
}

void process()
{
	int st, end;

	if ( query[ 0 ] == '*' )
	{
		st = 1;
		end = cnt;
	}
	else
	{
		char * tokenPtr;
		tokenPtr = strtok( query, " " );
		st = atoi( tokenPtr );
		tokenPtr = strtok( NULL, " " );
		if ( tokenPtr == NULL )
		{
			end = st;
		}
		else
		{
			end = atoi( tokenPtr );
		}
	}

	for ( int i = st; i <= end; i++ )
	{
		if ( i >= st + 1 )
		{
			cout << endl;
		}
		cout << "Size " << i << endl;
		backtrack( 0, i, "" );
	}
}

void backtrack( int stInd, int rem, string output )
{
	string tOut;
	for ( int i = stInd; i < cnt - (rem - 1); i++ )
	{
		tOut = output;
		tOut += names[ i ];
		if ( rem >= 2 )
		{
			tOut += ", ";
			backtrack( i + 1, rem - 1, tOut );
		}
		else
		{
			cout << tOut << endl;
		}
	}
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 598: Bundling eccentric newspapers

Post by brianfry713 » Fri Oct 12, 2012 11:35 pm

For this input posted by Jan:

Code: Select all

3

2 3
Times
Herald-Tribune
Post
New Advocate

*
abc
def

1
pqm
The AC output is:

Code: Select all

Size 2
Times, Herald-Tribune
Times, Post
Times, New Advocate
Herald-Tribune, Post
Herald-Tribune, New Advocate
Post, New Advocate

Size 3
Times, Herald-Tribune, Post
Times, Herald-Tribune, New Advocate
Times, Post, New Advocate
Herald-Tribune, Post, New Advocate


Size 1
abc
def

Size 2
abc, def


Size 1
pqm

Check input and AC output for thousands of problems on uDebug!

AhmadKhatar
New poster
Posts: 28
Joined: Fri Mar 30, 2012 12:57 am

Re: 598: Bundling eccentric newspapers

Post by AhmadKhatar » Sat Oct 13, 2012 12:03 am

So the sample output was wrong!
Many thanks!! :D

afruizc
New poster
Posts: 15
Joined: Sat Oct 13, 2012 2:04 am

Re: 598: Bundling eccentric newspapers

Post by afruizc » Tue Dec 04, 2012 10:45 am

I don't know what wrong with My code. I've reviewed it several times. It's passed all the test cases so far. I'm getting WA if anyone can help me I would really appreciate.

Code: Select all

Acc....
Removed after realizing a wasn't doing what was asked int the problem description

Zyaad Jaunnoo
Experienced poster
Posts: 122
Joined: Tue Apr 16, 2002 10:07 am

Re: 598 - Bundling Newspapers

Post by Zyaad Jaunnoo » Fri Oct 10, 2014 5:29 pm

Be careful with the output ( I got caught :-? ):
  • [1] Print a blank line AFTER each subset size group
    [2] Print a blank line BETWEEN datasets

Post Reply

Return to “Volume 5 (500-599)”