11340 - Newspaper
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11340 - Newspaper
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 5
- Joined: Thu Aug 09, 2012 11:09 pm
Re: 11340 - Newspaper
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
I really don't know what to do ...
here's the new code :
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

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.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11340 - Newspaper
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.
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!
-
- New poster
- Posts: 4
- Joined: Fri Jul 27, 2012 1:53 pm
Re: 11340 - Newspaper
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);
}
#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);
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11340 - Newspaper
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!
-
- New poster
- Posts: 5
- Joined: Thu Aug 09, 2012 11:09 pm
Re: 11340 - Newspaper
finally ,,, it worked !!!
I got ac !!!
thanks for help brianfry713
I got ac !!!
thanks for help brianfry713

Re: 11340 - Newspaper
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;
}
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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11340 - Newspaper
InputAC output:
Code: Select all
1
1
a 1
1
a
Code: Select all
0.01$
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 11
- Joined: Thu Apr 05, 2012 8:33 pm
Re: 11340 - Newspaper
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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11340 - Newspaper
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!
-
- New poster
- Posts: 11
- Joined: Mon Feb 20, 2012 11:04 am
Re: 11340 - Newspaper
Code: Select all
after a little bit change got AC
Re: 11340 - Newspaper
got WA in this, my code is at http://ideone.com/GETlkg.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11340 - Newspaper
your code doesn't work with trailing whitespace on a line.
Check input and AC output for thousands of problems on uDebug!
Re: 11340 - Newspaper
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....
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....
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11340 - Newspaper
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!