Page 9 of 11

### Re: 11340 - Newspaper

Posted: Mon Nov 11, 2013 11:24 pm
Don't use Scanner

### Re: 11340 - Newspaper

Posted: Wed Dec 04, 2013 1:36 am
do not understand why I get WA - Help me please.

Code: Select all

``````AC THANK YOU brianfry713
``````

### Re: 11340 - Newspaper

Posted: Thu Dec 05, 2013 12:57 am
Try using double instead of float.

### Re: 11340 - Newspaper

Posted: Sat Dec 07, 2013 5:56 pm
I have AC - but I have a question:

Why should use "double"?

### Re: 11340 - Newspaper

Posted: Tue Dec 10, 2013 4:16 am

### Re: 11340 - Newspaper

Posted: Mon Dec 16, 2013 9:03 pm
Why TLE , Plz help me anyone........

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

using namespace std;
char s[10005];

int main()
{
long long tc,line,num,value,i,array[155],l,sum;
char charr,c;
scanf("%lld",&tc);
while(tc--)
{
scanf("%lld",&num);
sum=0;
for(i=0;i<150;i++)
array=0;
while(num--)
{
cin>>charr>>value;
array[charr]=value;
}
scanf("%lld",&line);
while(line--)
{
scanf("%c",&c);
sum=sum+array[c];
gets(s);
l=strlen(s);
for(i=0;i<l;i++)
{
sum=sum+array[s];
}
}
double summ=(double)sum/(double)100.0;
long long int ll=summ;
double r=(double)ll+0.10;
if(summ>=r)
printf("%.2f\$\n",summ);
else
{
long long int f=100*(summ-ll);
printf("%lld.0%1lld\$\n",ll,f);
cout<<ll<<".0"<<f<<endl;
}
}
return 0;
}

### Re: 11340 - Newspaper

Posted: Tue Dec 17, 2013 10:57 pm
Don't assume that the characters in this problem have an ASCII value less than 128. Use an unsigned char.

### Re: 11340 - Newspaper

Posted: Fri Jul 25, 2014 10:53 pm
WA with 11340

### Re: 11340 - Newspaper

Posted: Fri Jul 25, 2014 10:56 pm
Whats wrong with my code? It does not produce any output, continue taking input.
My code:

Code: Select all

``````#include<stdio.h>
#include<string.h>
int main()
{
int t,p,line,len,i,j,k,val[110];
float sum,ans;
char art[10020], ch[110];
scanf("%d",&t);
while(t--)
{
sum=0;
scanf("%d",&p);
for(i=0;i<p;i++)
scanf("%c %d",&ch[i],&val[i]);

scanf("%d",&line);

while(line--)
{
gets(art);
len=strlen(art);
for(i=0;i<len;i++)
{
for(j=0;j<p;j++)
{
if(art[i]==ch[i])
{
sum+=val[i];
break;
}
}
}
}
ans=sum/100;
printf("%.2f\n",ans);
}
return 0;
}
``````

### Re: 11340 - Newspaper

Posted: Sat Jul 26, 2014 12:30 am
First character it reads is newline character which comes after reading line.
Remember this when you try to read strings and chars. Check that you already have read newline before them.

You can do like this to read newline

Code: Select all

``````scanf("%d",&line);
while (getchar() != '\n');``````

Code: Select all

``````for(i=0;i<p;i++)
{
while (getchar() != '\n');
scanf("%c %d",&ch[i],&val[i]);
}``````
Change this to

Code: Select all

``````if(art[i]==ch[j])
{
sum+=val[j];
break;
}``````
Print \$ at the end.

### Re: 11340 - Newspaper

Posted: Sun Aug 03, 2014 4:02 pm
I got Runtime error, and i'm not sure if it's because of spacing, or overflow, or both. Help?

Code: Select all

``````code deleted. Thanks lbv!
``````

### Re: 11340 - Newspaper

Posted: Sun Aug 03, 2014 7:03 pm
dTanMan wrote:I got Runtime error, and i'm not sure if it's because of spacing, or overflow, or both. Help?
Carefully check this fragment of code:

Code: Select all

``````         int numLines = Integer.parseInt(br.readLine());

for(int j=0; j<numLetters; j++)
``````
Is numLetters the variable you meant to use in that loop?

Keep in mind that you can always go back to previous messages in the forums (this thread is pretty long, for example) and look for test cases that others have left before, and that can usually help you discover this kind of problems.

I think using two hashmaps may be too slow. You could try using a simple array indexed by the integer value of each character (but beware that not all characters are ASCII, see previous messages).

### Re: 11340 - Newspaper

Posted: Fri Oct 17, 2014 8:14 pm

Code: Select all

``Lots of thanks to brianfry713.``

### Re: 11340 - Newspaper

Posted: Fri Oct 17, 2014 10:55 pm
Change:
value[(int)c] = d;
to:
value[(int)c+128] = d;

Change:
t += value[d];
to:
t += value[(int)d+128];

### Re: 11340 - Newspaper

Posted: Tue Nov 18, 2014 9:40 am
Why WA?

Code: Select all

``````#include <iostream>
#include<string>
#include <string.h>
#include<map>
#include<stdio.h>
using namespace std;
long int n,i,j,k,d,h;
double sum;
char c,s[10010],aux,aux2;
map <char,long int> mapa;
map <char,long int>::iterator it;
int main()
{
scanf("%d",&n);
for (i=0;i<n;i++){
scanf("%d%c",&k,&aux);
for (j=0;j<k;j++){
scanf("%c%c%d%c",&c,&aux,&d,&aux2);
mapa[c]=d;
}
scanf("%d\n",&k);
for (h=0;h<k;h++){
scanf("%[^\n]",&s);
scanf("%c",&c);
for (j=0;j<strlen(s);j++){
sum+=mapa[s[j]];
}
}
printf("%.2f\$",sum/100);
mapa.clear();
sum=0;
}
return 0;
}``````