11340 - Newspaper

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

Moderator: Board moderators

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 11340 - Newspaper

Post by Obaida » Wed Jan 07, 2009 8:15 am

Please help me.. So many WA!!!!

Code: Select all

removed
Last edited by Obaida on Sun Aug 09, 2009 5:06 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 11340 - Newspaper

Post by Obaida » Thu Jan 29, 2009 12:24 pm

Some one plz reply..... :oops:
try_try_try_try_&&&_try@try.com
This may be the address of success.

User avatar
kbr_iut
Experienced poster
Posts: 103
Joined: Tue Mar 25, 2008 11:00 pm
Location: IUT-OIC, DHAKA, BANGLADESH
Contact:

Re: 11340 - Newspaper

Post by kbr_iut » Fri Jan 30, 2009 1:00 am

u r having problem coz of overfloaw.
according to the problem ur sum variable may contain...
150000*10000*1000 = 1500000000000 which cant be supported within long or int range.........

i used a trick....when sum exceeds 100 make it dollar and keep it to another variable var...
then i just printed var and sum...
secondly ur program is printing some extra newline and there is also a problem handling extra space and newline.

i modified ur code a bit. open ur inbox.u coud see...( hey man.....it takes a unsigned long long time to find the actualy bug)

anyway.....keep posting.
It is tough to become a good programmer.
It is more tough to become a good person.
I am trying both...............................

calicratis19
Learning poster
Posts: 76
Joined: Mon Jul 21, 2008 8:50 am
Location: SUST,SYLHET,BANGLADESH.
Contact:

Re: 11340 - Newspaper

Post by calicratis19 » Fri Aug 07, 2009 10:24 am

to clear up the confusion

1)long is enough.
2)unsigned char is needed.

i got wa for the way i printed output.

in my ac code i used
printf("%ld.%02ld$\n",dollar,cents);
and then i got ac.

hope it helps.
Heal The World

amishera
New poster
Posts: 38
Joined: Sat Dec 27, 2008 10:42 pm

Re: 11340 - Newspaper

Post by amishera » Tue Apr 20, 2010 4:18 am

From the above posts, many comments conflict with each other. Some people are saying char is enough, some is saying unsigned char is required. Some are saying to use long long, some are saying int is enough. Which one is correct actually? See I used this according to some suggestions made before:

Code: Select all

#include <stdio.h>
#include <string.h>

[b]#define to_unsigned_char(x) if (x < 0) x += 256[/b]
int table[1000000];

int main()
{		
	char article[1000000];
	int n;
	int k;
[b]	char c;[/b]
	int p;
	int m;
	int len;
	long long sum_dollar;
	int sum_cents;
	int i;
	int j;
	int t;
	scanf(" %d",&n);
	int first = 1;

	while (n-- > 0)
	{
		scanf(" %d",&k);
		for (j = 0;j < 512;j++)
		{
			table[j] = 0;
		}

		while (k-- > 0)
		{			
		[b]	scanf(" %c %d",&c, &p);
			t = c;	
			to_unsigned_char(t);
			table[(int)t] = p;[/b]
		}

		scanf("%d",&m);

		sum_dollar = 0;
		sum_cents = 0;
		while (m-- > 0)
		{
			scanf(" %[^\n]",article);
			for (k = 0;article[k];k++)
			{
				[b]t = article[k];
				to_unsigned_char(t);
				sum_cents += table[t];
				if (sum_cents >= 100) {
					sum_cents -= 100;
					sum_dollar++;
				}[/b]
			}
		}
		[b]printf("%lld", sum_dollar);
		if (sum_cents > 0)
		{
			printf(".%2d$\n", sum_cents);
		}
		else
		{
			printf(".0$\n");
		}[/b]
	}
	return 0;
}
The part in bold demonstrate the suggestions (which are consistent with each other) incorporated in the code (unsigned char, long long, separate variables for dollars and cents). But still that mf idiot judge is giving wrong answer. Sometimes I feel like to spank this mean judge.

Now what to do?

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 11340 - Newspaper

Post by sohel » Tue Apr 20, 2010 9:43 am

I have solved this problem a long time ago.
But from what i remember, you have to use 'unsigned char' for reading the 'paid characters'.

and for this part - printf(".%2d$\n", sum_cents);
shouldn't it be printf(".%02d$\n", sum_cents);

amishera
New poster
Posts: 38
Joined: Sat Dec 27, 2008 10:42 pm

Re: 11340 - Newspaper

Post by amishera » Wed Apr 21, 2010 5:19 am

I made the format string to %02d and also made the unsigned character as mentioned here:

http://online-judge.uva.es/board/viewto ... 4&start=15

Code: Select all

#include <stdio.h>
#include <string.h>
#include <iostream>

using namespace std;

#define to_unsigned_char(x) if (x < 0) x += 256
int table[1000000];

int main()
{		
	char article[1000000];
	...
	unsigned char c;
        ...
	long long sum_dollar;
	int sum_cents;
        ...
	while (k-- > 0)
	{	
			c = cin.get(); //to skip whitespaces
			c = cin.get(); // get the char					
			t = c;            // convert it to int
			to_unsigned_char(t);		
			cin >> p;
			table[(int)t] = p;
	}
...
	while (m-- > 0)
	{
			scanf(" %[^\n]",article);
			for (k = 0;article[k];k++)
			{
				t = article[k];
				to_unsigned_char(t);
				sum_cents += table[t];
				if (sum_cents >= 100) {
					sum_cents -= 100;
					sum_dollar++;
				}
			}		
        }
...
	printf("%lld.%02d$\n", sum_dollar, sum_cents);[/u]
	

Still no right answer. I am not sure whether the reading the paragraph is the right procedure. Because it is reading a string using scanf(" %[^\n]"). Now you can't blame me that I didn't read the posts. I read the posts and made the necessary suggestions as well. But this anal retentive ACM judge is badgering me.

amishera
New poster
Posts: 38
Joined: Sat Dec 27, 2008 10:42 pm

Re: 11340 - Newspaper

Post by amishera » Wed Apr 21, 2010 5:40 am

I made the final code which seems to be fool-proof because now both the table and the paragraph are read as unsigned char:

Code: Select all

#include <stdio.h>
#include <string.h>
#include <iostream>

using namespace std;

#define to_unsigned_char(x) if (x < 0) x += 256
int table[1000000];

int main()
{		
	unsigned char article[1000000];
	int n;
	int k;
	unsigned char c;
	int p;
	int m;
	int len;
	long long sum_dollar;
	int sum_cents;
	int i;
	int j;
	int t;
	scanf(" %d",&n);
	int first = 1;

	while (n-- > 0)
	{
		scanf(" %d",&k);
		for (j = 0;j < 512;j++)
		{
			table[j] = 0;
		}

		[b]while (k-- > 0)
		{	
			c = cin.get();
			c = cin.get();					
			t = c;
//			to_unsigned_char(t);			
			cin >> p;
			table[(int)t] = p;
		}[/b]

		scanf("%d",&m);

		sum_dollar = 0;
		sum_cents = 0;
		c = cin.get();
		while (m-- > 0)
		{
			[b]while ((c = cin.get()) != '\n')
			{				
				t = c;
	//			printf("c: %c\n", c);
//				to_unsigned_char(t);
				sum_cents += table[t];
				if (sum_cents >= 100) {
					sum_cents -= 100;
					sum_dollar++;
				}
			}[/b]
		}
		printf("%lld.%02d$\n", sum_dollar, sum_cents);
//		if (sum_cents > 0)
//		{
//			printf(".%02d$\n", sum_cents);
//		}
//		else
//		{
//			printf(".0$\n");
//		}
	}
	return 0;
}
Still the same old thing. I am totally pissed off with this ahole judge.

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 11340 - Newspaper

Post by sohel » Wed Apr 21, 2010 1:11 pm

Try avoiding scanf() altogether for this problem.
Use gets() and sscanf().

And btw, this online-judge aint retarded. It just compiles your program and runs it with the judge data - then compares your output with that of the judge answer file.

amishera
New poster
Posts: 38
Joined: Sat Dec 27, 2008 10:42 pm

Re: 11340 - Newspaper

Post by amishera » Thu Apr 22, 2010 1:08 am

I am not sure why scanf wouldn't work but sscanf would work. Because the format strings are the same for both. The problem seems to boil down to how to input an unsigned char. So I resorted to the "cin" as suggested in previous posts for the problemetic parts (character reading). But still no change of my plight.

faiem
New poster
Posts: 14
Joined: Fri Aug 13, 2010 12:22 pm

Re: 11340 - Newspaper

Post by faiem » Fri Nov 12, 2010 2:53 pm

:D
In this problem must use "unsigned char"...Or u will get WA...again and again just like me.
:oops:

JeanBez
New poster
Posts: 1
Joined: Mon Nov 22, 2010 12:39 am

Re: 11340 - Newspaper

Post by JeanBez » Mon Nov 22, 2010 12:46 am

I used string, map and unsiged char only in the first part while reading letter and the coast and got AC.
:D

live_lie
New poster
Posts: 19
Joined: Mon Nov 29, 2010 11:50 pm

Re: 11340 - Newspaper

Post by live_lie » Wed Jun 15, 2011 7:34 pm

thank you all...i have an AC now thanks a lot.

Garfield
New poster
Posts: 2
Joined: Thu Nov 03, 2011 1:54 pm

Re: 11340 - Newspaper

Post by Garfield » Thu Nov 03, 2011 1:57 pm

Always wanted to have AC. Thank you, your help is very much spy phone appreciated!
Last edited by Garfield on Fri Feb 03, 2012 8:32 am, edited 1 time in total.

shakil ahmed
New poster
Posts: 3
Joined: Wed Oct 12, 2011 5:20 am

Re: 11340 - Newspaper

Post by shakil ahmed » Mon Nov 07, 2011 11:47 am

why WA???? plz help me............... :(

#include <stdio.h>
#include <string.h>
char str[10100];
int main()
{
int t,k;
scanf("%d",&t);
getchar();
for(k=1;k<=t;k++)
{
int a[260]={0},j,d,m,i,n;
char ch;
scanf("%d",&m);
getchar();
for(i=1;i<=m;i++)
{
scanf("%c %d",&ch,&d);
getchar();
a[ch]=d;
}
scanf("%d",&n);
getchar();
long long int sum=0,var=0;
for(i=1;i<=n;i++)
{
gets(str);
int len=strlen(str);
for(j=0;j<len;j++)
if(a[str[j]]>0)
sum+=a[str[j]];
if(sum>=100)
{
sum=0;
var++;
}

}
printf("%lld\.%lld$\n",var,sum);
}
return 0;
}

Post Reply

Return to “Volume 113 (11300-11399)”