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

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

Re: 11340 - Newspaper

Post by brianfry713 » Mon Nov 11, 2013 11:24 pm

Don't use Scanner
Check input and AC output for thousands of problems on uDebug!

Kenpachi24
New poster
Posts: 20
Joined: Wed Oct 30, 2013 7:06 pm

Re: 11340 - Newspaper

Post by Kenpachi24 » Wed Dec 04, 2013 1:36 am

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.

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

Re: 11340 - Newspaper

Post by brianfry713 » Thu Dec 05, 2013 12:57 am

Try using double instead of float.
Check input and AC output for thousands of problems on uDebug!

Kenpachi24
New poster
Posts: 20
Joined: Wed Oct 30, 2013 7:06 pm

Re: 11340 - Newspaper

Post by Kenpachi24 » Sat Dec 07, 2013 5:56 pm

I have AC - but I have a question:

Why should use "double"?

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

Re: 11340 - Newspaper

Post by brianfry713 » Tue Dec 10, 2013 4:16 am

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

imtiaz_ice
New poster
Posts: 1
Joined: Sun Dec 15, 2013 8:49 am

Re: 11340 - Newspaper

Post by imtiaz_ice » 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;
}

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

Re: 11340 - Newspaper

Post by brianfry713 » 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.
Check input and AC output for thousands of problems on uDebug!

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 11340 - Newspaper

Post by Shahidul.CSE » Fri Jul 25, 2014 10:53 pm

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

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 11340 - Newspaper

Post by Shahidul.CSE » 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;
}
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

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 11340 - Newspaper

Post by lighted » Sat Jul 26, 2014 12:30 am

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

Code: Select all

scanf("%d",&line);
while (getchar() != '\n');
Also add this before reading characters.

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.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

dTanMan
New poster
Posts: 5
Joined: Sat Feb 01, 2014 5:22 am

Re: 11340 - Newspaper

Post by dTanMan » 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!
Last edited by dTanMan on Fri Oct 31, 2014 11:24 am, edited 1 time in total.

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

Re: 11340 - Newspaper

Post by lbv » 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++)
            process(br.readLine(), hm);
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).

ehsanulbigboss
New poster
Posts: 32
Joined: Tue Jul 22, 2014 1:17 am

Re: 11340 - Newspaper

Post by ehsanulbigboss » Fri Oct 17, 2014 8:14 pm

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.

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

Re: 11340 - Newspaper

Post by brianfry713 » Fri Oct 17, 2014 10:55 pm

Read this thread.
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!

marcom
New poster
Posts: 1
Joined: Tue Nov 18, 2014 8:51 am

Re: 11340 - Newspaper

Post by marcom » 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;
}

Post Reply

Return to “Volume 113 (11300-11399)”