Page 6 of 11
Re: 11340 - Newspaper
Posted: Mon Aug 13, 2012 11:16 pm
by brianfry713
Re: 11340 - Newspaper
Posted: Wed Aug 15, 2012 1:24 am
by truthSeeker
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 :
Re: 11340 - Newspaper
Posted: Wed Aug 15, 2012 10:57 pm
by brianfry713
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.
Re: 11340 - Newspaper
Posted: Thu Aug 16, 2012 9:55 pm
by sulaimansust
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);
}
Re: 11340 - Newspaper
Posted: Thu Aug 16, 2012 11:48 pm
by brianfry713
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.
Re: 11340 - Newspaper
Posted: Fri Aug 17, 2012 6:45 am
by truthSeeker
finally ,,, it worked !!!
I got ac !!!
thanks for help brianfry713

Re: 11340 - Newspaper
Posted: Sat Aug 18, 2012 12:39 pm
by ALONE
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;
}
Re: 11340 - Newspaper
Posted: Mon Aug 20, 2012 10:25 pm
by brianfry713
Re: 11340 - Newspaper
Posted: Fri Nov 30, 2012 8:54 pm
by shatil_cse
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;
}
Re: 11340 - Newspaper
Posted: Sat Dec 08, 2012 7:49 am
by brianfry713
Don't use a single getchar() and count on it to be a newline. There may be trailing whitespace on a line.
Re: 11340 - Newspaper
Posted: Thu Dec 13, 2012 11:14 am
by asitmahato
Re: 11340 - Newspaper
Posted: Sat Dec 15, 2012 7:37 pm
by gr81
got WA in this, my code is at
http://ideone.com/GETlkg.
Re: 11340 - Newspaper
Posted: Sat Dec 15, 2012 11:13 pm
by brianfry713
your code doesn't work with trailing whitespace on a line.
Re: 11340 - Newspaper
Posted: Wed Dec 19, 2012 8:20 am
by gr81
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....
Re: 11340 - Newspaper
Posted: Wed Dec 19, 2012 11:18 pm
by brianfry713
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);
...