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

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

Re: 11340 - Newspaper

Post by brianfry713 » Mon Aug 13, 2012 11:16 pm

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

truthSeeker
New poster
Posts: 5
Joined: Thu Aug 09, 2012 11:09 pm

Re: 11340 - Newspaper

Post by truthSeeker » Wed Aug 15, 2012 1:24 am

it seems that with gcc , istream::sync() doesn't work in the same way it does with VC++2010 ... that's what made the output difference between my snapshot and ideone ...
anyway , i got rid of sync() and adjusted the code , and it gave me TLE :(
so , I re-wrote the entire code using standard I/O functions (printf and scanf) instead of using streams , as stdio functions are a little faster than streams ... i submitted that code and it gave me WA :x
I really don't know what to do ...
here's the new code :

Code: Select all

GOT AC :))
Last edited by truthSeeker on Fri Aug 17, 2012 6:41 am, edited 1 time in total.

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

Re: 11340 - Newspaper

Post by brianfry713 » Wed Aug 15, 2012 10:57 pm

I'm not sure if all of these changes are necessary, but it will get you AC.
Change test[] and val to unsigned long long.
Use only unsigned chars.
Read all input line by line.
Check input and AC output for thousands of problems on uDebug!

sulaimansust
New poster
Posts: 4
Joined: Fri Jul 27, 2012 1:53 pm

Re: 11340 - Newspaper

Post by sulaimansust » Thu Aug 16, 2012 9:55 pm

This is my code. It Output the reult for given test but I still getting wrong ans. Plz somebody help me to debug

#include <stdio.h>
#include <string.h>
long long int cent=0;
double dollar;
int kee, mee, id;
char sign = '$';
void cost(char array[], char paid[], int paidi[]);
double cent_dollar(long int cent);
int main()
{
int n, k, i, j, w;
long int m;
char news[10010];

scanf("%d", &n);
for(w=1; w<=n; w++)
{
scanf("%d", &k);
getchar();

char paid[k];
int paidi[k];

for(i=0; i<k; ++i)
{
scanf("%c %d", &paid, &paidi);
getchar();
}
scanf("%ld", &m);
getchar();


kee = k;
mee = m;

for(i=0; i<m; i++)
{
id=i;
gets(news);
cost(news, paid, paidi);
}
dollar = cent_dollar(cent);
printf("%0.2lf%c", dollar, sign);

}
return 0;
}
void cost(char array[], char paid[], int paidi[])
{
int length, l, m;

length = strlen(array);
for(l=0; l<length; ++l)
{
for(m=0; m<kee; ++m)
{
if(paid[m]==array[l])
{
cent+=paidi[m];
break;
}
else
{
cent +=0;
}
}
}



return;
}

double cent_dollar(long int cent)
{
double centind = cent * 1.0;
dollar = centind/100;
return(dollar);

}

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

Re: 11340 - Newspaper

Post by brianfry713 » Thu Aug 16, 2012 11:48 pm

Code: Select all

2
7
a 3
W 10
A 100
, 10
k 7
. 3
I 13
7
ACM International Collegiate Programming Contest (abbreviated
as ACM-ICPC or just ICPC) is an annual multi-tiered competition
among the universities of the world. The ICPC challenges students
to set ever higher standards of excellence for themselves
through competition that rewards team work, problem analysis,
and rapid software development.
From Wikipedia.
7
a 3
W 10
A 100
, 10
k 7
. 3
I 13
7
ACM International Collegiate Programming Contest (abbreviated
as ACM-ICPC or just ICPC) is an annual multi-tiered competition
among the universities of the world. The ICPC challenges students
to set ever higher standards of excellence for themselves
through competition that rewards team work, problem analysis,
and rapid software development.
From Wikipedia.
Check input and AC output for thousands of problems on uDebug!

truthSeeker
New poster
Posts: 5
Joined: Thu Aug 09, 2012 11:09 pm

Re: 11340 - Newspaper

Post by truthSeeker » Fri Aug 17, 2012 6:45 am

finally ,,, it worked !!!
I got ac !!!
thanks for help brianfry713 :)

ALONE
New poster
Posts: 1
Joined: Sat Aug 18, 2012 12:35 pm

Re: 11340 - Newspaper

Post by ALONE » Sat Aug 18, 2012 12:39 pm

whats wrong with dis code ??
using namespace std;
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
int main()
{
unsigned long long t;
cin>>t;
while(t--)
{
unsigned long long int n,i,line,tot=0,temp=0;
cin>>n;
unsigned char paid[n],y;
unsigned int value[n];
for(i=0;i<n;i++)
{
scanf("\n%c %d",&paid,&value);
}
cin>>line;
while(temp<=line)
{
while((y=getchar())!='\n' && y!=EOF)
{
for(i=0;i<n;i++)
{
if(paid==y)
tot=tot+value;
}
}
temp++;
}
cout<<tot/100<<"."<<tot%100<<"$"<<endl;
}
return 0;
}

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

Re: 11340 - Newspaper

Post by brianfry713 » Mon Aug 20, 2012 10:25 pm

Input

Code: Select all

1
1
a 1
1
a
AC output:

Code: Select all

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

shatil_cse
New poster
Posts: 11
Joined: Thu Apr 05, 2012 8:33 pm

Re: 11340 - Newspaper

Post by shatil_cse » Fri Nov 30, 2012 8:54 pm

Please help me.....I can't find any wrong in my code

Code: Select all

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	char str[10001],c;
	long long i,j,k,l,m,n;
	double x;
	scanf("%lld",&l);
	for(j=1;j<=l;j++)
	{
		int value[500]={0};
		scanf("%lld",&m);
		for(i=1;i<=m;i++)
		{
			getchar();
			scanf("%d",&value[getchar()]);
		}
		scanf("%lld",&m);
		getchar();
		unsigned long long total;
		total=0;
		for(i=1;i<=m;i++)
		{
			gets(str);
			k=strlen(str);
			for(n=0;n<k;n++) total+=value[str[n]];
		}
		x=double(total);
		printf("%0.2lf$\n",x/100);
	}
	return 0;
}

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

Re: 11340 - Newspaper

Post by brianfry713 » Sat Dec 08, 2012 7:49 am

Don't use a single getchar() and count on it to be a newline. There may be trailing whitespace on a line.
Check input and AC output for thousands of problems on uDebug!

asitmahato
New poster
Posts: 11
Joined: Mon Feb 20, 2012 11:04 am

Re: 11340 - Newspaper

Post by asitmahato » Thu Dec 13, 2012 11:14 am

Code: Select all

after a little bit change got AC
run time error.

gr81
New poster
Posts: 46
Joined: Wed Sep 26, 2012 7:52 pm

Re: 11340 - Newspaper

Post by gr81 » Sat Dec 15, 2012 7:37 pm

got WA in this, my code is at http://ideone.com/GETlkg.

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

Re: 11340 - Newspaper

Post by brianfry713 » Sat Dec 15, 2012 11:13 pm

your code doesn't work with trailing whitespace on a line.
Check input and AC output for thousands of problems on uDebug!

gr81
New poster
Posts: 46
Joined: Wed Sep 26, 2012 7:52 pm

Re: 11340 - Newspaper

Post by gr81 » Wed Dec 19, 2012 8:20 am

if i don't have any cost for spaces, I think it will not affect the total cost.
in case publisher is charging for spaces too, how would I specify the cost of spaces..like we are doing it for other char.

A 100
, 10
<-------IS THERE ANY SYNTAX FOR THAT.

Could you please explain more....

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

Re: 11340 - Newspaper

Post by brianfry713 » Wed Dec 19, 2012 11:18 pm

I meant to change the way you parse the input. Here's what I did to get AC in ANSI C:

Code: Select all

unsigned char c, line[10010];
int val;
...
gets(line);
sscanf(line,"%c %d",&c,&val);
...
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 113 (11300-11399)”