11340 - Newspaper
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11340 - Newspaper
Don't use Scanner
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 20
- Joined: Wed Oct 30, 2013 7:06 pm
Re: 11340 - Newspaper
do not understand why I get WA - Help me please.
Code: Select all
AC THANK YOU brianfry713
Last edited by Kenpachi24 on Sat Dec 07, 2013 5:54 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11340 - Newspaper
Try using double instead of float.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 20
- Joined: Wed Oct 30, 2013 7:06 pm
Re: 11340 - Newspaper
I have AC - but I have a question:
Why should use "double"?
Why should use "double"?
-
- 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: 1
- Joined: Sun Dec 15, 2013 8:49 am
Re: 11340 - Newspaper
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;
}
#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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11340 - Newspaper
Don't assume that the characters in this problem have an ASCII value less than 128. Use an unsigned char.
Check input and AC output for thousands of problems on uDebug!
-
- Experienced poster
- Posts: 148
- Joined: Sun Jul 13, 2014 4:32 am
- Location: Rangpur, Bangladesh
Re: 11340 - Newspaper
WA with 11340
Last edited by Shahidul.CSE on Fri Jul 25, 2014 10:58 pm, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
-
- Experienced poster
- Posts: 148
- Joined: Sun Jul 13, 2014 4:32 am
- Location: Rangpur, Bangladesh
Re: 11340 - Newspaper
Whats wrong with my code? It does not produce any output, continue taking input.
My code:
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;
}
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Re: 11340 - Newspaper
After reading line it reads art.
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
Also add this before reading characters.
Change this to
Print $ at the end.
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]);
}
Code: Select all
if(art[i]==ch[j])
{
sum+=val[j];
break;
}
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Re: 11340 - Newspaper
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!
Last edited by dTanMan on Fri Oct 31, 2014 11:24 am, edited 1 time in total.
Re: 11340 - Newspaper
Carefully check this fragment of code:dTanMan wrote:I got Runtime error, and i'm not sure if it's because of spacing, or overflow, or both. Help?
Code: Select all
int numLines = Integer.parseInt(br.readLine());
for(int j=0; j<numLetters; j++)
process(br.readLine(), hm);
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).
-
- New poster
- Posts: 32
- Joined: Tue Jul 22, 2014 1:17 am
Re: 11340 - Newspaper
Why Getting WA?? Please Help.
Code: Select all
Lots of thanks to brianfry713.
Last edited by ehsanulbigboss on Sat Oct 18, 2014 9:09 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11340 - Newspaper
Read this thread.
Change:
value[(int)c] = d;
to:
value[(int)c+128] = d;
Change:
t += value[d];
to:
t += value[(int)d+128];
Change:
value[(int)c] = d;
to:
value[(int)c+128] = d;
Change:
t += value[d];
to:
t += value[(int)d+128];
Check input and AC output for thousands of problems on uDebug!
Re: 11340 - Newspaper
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;
}