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

Post Reply
arunanshu
New poster
Posts: 1
Joined: Tue Jan 24, 2012 8:50 pm

Re: 11340 - Newspaper

Post by arunanshu » Tue Jan 24, 2012 8:53 pm

Got a wrong answer....
Can any one help? I tried with all the inputs that i could gather. It seems to provide the correct results :

Code: Select all

#include<iostream>
#include<cmath>
#include<vector>
#define fir(i,x) for(int i=0;i<x;i++)
#define ll long long
using namespace std;

int main(){
    
    ll n,k,m;
    cin>>n;
    fir(i,n){
             vector<int> charValue(256,0);
             // rate
             cin>>k;
             fir(j,k){
                      char ch;
                      ll val;
                      cin>>ch>>val;
                      
                      charValue[(int)ch] = val;                
                      }
             cin>>m;
             //cin.ignore (80, '\n');
             ll sum = 0;
             string str;
             fir(l,m){
                      getline(cin,str);
                      fir(x,str.size()) sum = sum + charValue[(int)str[x]];
                      
                      
                      }
           //  cout.precision(2);
           
              
           
             cout<<fixed<<sum/100<<"."<<sum%100<<"$"<<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 » Wed Jan 25, 2012 2:42 am

This fails for the sample input.
Check input and AC output for thousands of problems on uDebug!

Achilies_Saiful_Buet
New poster
Posts: 16
Joined: Wed Mar 28, 2012 7:24 pm
Location: Dhaka,Bangladesh

Re: 11340 - Newspaper

Post by Achilies_Saiful_Buet » Wed Mar 28, 2012 7:35 pm

Plzzzzzzzzz helppppp!!!!!!!!!..
From some previous post,some said that leading zero like 1.00$ is a problem but i checked UVA toolkit and there this wasn't a problem.but btw i've also checked my code by truncating that zero .but WA WA WA!!!!! :x :x plzz help me out....
Last edited by Achilies_Saiful_Buet on Thu Mar 29, 2012 8:27 am, 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 Mar 29, 2012 1:09 am

My AC code doesn't use doubles until the final print statement, try using unsigned long long int for sum and int for the characters values.
Check input and AC output for thousands of problems on uDebug!

Achilies_Saiful_Buet
New poster
Posts: 16
Joined: Wed Mar 28, 2012 7:24 pm
Location: Dhaka,Bangladesh

Re: 11340 - Newspaper

Post by Achilies_Saiful_Buet » Thu Mar 29, 2012 8:25 am

Finally got accepted :) thnx brianfry713 for ur kind suggestion but i was still getting WA.....
My main problem was taking the string input by gets() and using string and casting it to unsigned. when i debugged my code i saw that there was no casting in unsigned form
So my suggestion is --not take input with gets()....and string using is unnecessary...just reading lines with getchar() is enough.....

sith
Learning poster
Posts: 72
Joined: Sat May 19, 2012 7:46 pm

Re: 11340 - Newspaper

Post by sith » Sat May 26, 2012 11:26 am

Hello!

I always get WA.
I've tried all cases from this thread, and as I understood, the received results are correct.

I think that problem is in the result formating but I don't know what it is!


Please help!!!!!!!!

Here is my code:

Code: Select all

Karamba
Last edited by sith on Tue Jun 05, 2012 1:51 pm, edited 1 time in total.

SyFyKid
New poster
Posts: 26
Joined: Tue May 08, 2012 9:47 am

Re: 11340 - Newspaper

Post by SyFyKid » Tue May 29, 2012 4:55 pm

hello!

hmmm... you can write much shorter

Code: Select all

long left = sum % 100;

                    DecimalFormat formatter = new DecimalFormat();
                    formatter.setCurrency(Currency.getInstance(Locale.US));
                    if (left > 9) {
                        formatter.setMaximumFractionDigits(2);
                        formatter.setMinimumFractionDigits(2);

                    } else {
                        formatter.setMaximumFractionDigits(2);
                        formatter.setMinimumFractionDigits(1);
                    }
                    System.out.println(formatter.format((double) sum / 100) + "$");
like:

Code: Select all

System.out.printf("%.2f$\n", totalSum/100.0);
sith wrote:Hello!

I always get WA.
I've tried all cases from this thread, and as I understood, the received results are correct.

I think that problem is in the result formating but I don't know what it is!


Please help!!!!!!!!

Here is my code:

Code: Select all

class Main {
    public static void main(String[] args) {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        String line;
        try {
            while ((line = reader.readLine()) != null) {
                int caseNumber = Integer.parseInt(line);
                for (int i = 0; i < caseNumber; i++) {
                    Map<Integer, Integer> charactersPrice = new HashMap<Integer, Integer>();
                    int alphabetCount = Integer.parseInt(reader.readLine());
                    for (int j = 0; j < alphabetCount; j++) {
                        StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
                        charactersPrice.put((int)tokenizer.nextToken().toCharArray()[0], Integer.parseInt(tokenizer.nextToken()));
                    }

                    long linesCount = Long.parseLong(reader.readLine());

                    long sum = 0;
                    for (long j = 0; j < linesCount; j++) {
                        String textLine = reader.readLine();
                        for (char c : textLine.toCharArray()) {
                            Integer price = charactersPrice.get((int)c);
                            if (price != null) {
                                sum += price;
                            }
                        }
                    }

                    long left = sum % 100;

                    DecimalFormat formatter = new DecimalFormat();
                    formatter.setCurrency(Currency.getInstance(Locale.US));
                    if (left > 9) {
                        formatter.setMaximumFractionDigits(2);
                        formatter.setMinimumFractionDigits(2);

                    } else {
                        formatter.setMaximumFractionDigits(2);
                        formatter.setMinimumFractionDigits(1);
                    }
                    System.out.println(formatter.format((double) sum / 100) + "$");
                }
            }
        } catch (IOException e) {
        }
    }
}

sith
Learning poster
Posts: 72
Joined: Sat May 19, 2012 7:46 pm

Re: 11340 - Newspaper

Post by sith » Tue Jun 05, 2012 1:52 pm

Thanks a lot
It works!!!

User avatar
mahade hasan
Learning poster
Posts: 87
Joined: Thu Dec 15, 2011 3:08 pm
Location: University of Rajshahi,Bangladesh

Re: 11340 - Newspaper

Post by mahade hasan » Tue Jun 05, 2012 7:10 pm

why WA plz help me!!

Code: Select all

#include<stdio.h>

int main()
{
   double Dollar;
   long I,K,M,N,Test,Value;
   char C;
   scanf("%ld",&Test);
   for(;Test>0;Test--)
   {
      scanf("%ld",&N);
      int Arry[300]={0};
      for(I=1;I<=N;I++)
      {
         scanf("\n");
         scanf("%c %ld",&C,&Value);
         Arry[C]=Value;
      }
      Dollar=0;
      scanf("%ld",&N);
      for(I=1;I<=N;I++)
      {
         scanf("\n");
         while(scanf("%c",&C)&&C!='\n')
         Dollar+=Arry[C];
      }
      Dollar/=100;
      printf("%0.2lf$\n",Dollar);
      
   }
   return 0;
}
[/color]
we r surrounded by happiness
need eyes to feel it!

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

Re: 11340 - Newspaper

Post by brianfry713 » Tue Jun 05, 2012 9:30 pm

My AC code doesn't use doubles until the final print statement, try using unsigned long long int for sum and int for the characters values.
Check input and AC output for thousands of problems on uDebug!

esharif
New poster
Posts: 18
Joined: Sun Jun 03, 2012 11:56 pm

getting WA for 11340, help plz

Post by esharif » Wed Jul 04, 2012 12:21 am

Code: Select all

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

int main()
{
    long long int c, i, j, K, N, M, p, pos, sum, a[102];
    double result;
    char nws[10002], b[105], ch;
    while(scanf("%lld",&N)==1)
    {
        for(i=1; i<=N; i++)
        {
            sum=0;
            scanf("%lld", &K);
            for(j=0; j<K; j++)
            {
                scanf("\n%c", &b[j]);
                scanf("%lld", &a[j]);
            }
            scanf("%lld", &M);
            for(j=1; j<=M; j++)
            {
                memset(nws, '\0', sizeof(nws));
                scanf("\n");
                gets(nws);
                for(c=0; nws[c]!='\0'; c++)
                {
                    for(p=0;p<K;p++)
                    {
                        if(nws[c]==b[p])
                        {
									 sum+=a[p];
                            break;

                        }
                    }
                }
            }
            result=(double)sum;
            result/=100;
            printf("%.2f$\n", result);
        }
    }
    return 0;
}

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

Re: getting WA for 11340, help plz

Post by brianfry713 » Fri Jul 06, 2012 1:48 am

printf("%.2lf$\n", result);

A double is %lf, a float is %f
Check input and AC output for thousands of problems on uDebug!

truthSeeker
New poster
Posts: 5
Joined: Thu Aug 09, 2012 11:09 pm

Re: 11340 - Newspaper

Post by truthSeeker » Thu Aug 09, 2012 11:21 pm

I've read all the discussion here ...
my code passes every IO test i know (the one in the problem statement , and the two mentioned here) ...
but still , my code gets WA !!!
i can't get to figure out what the problem is ...
here's my code :

Code: Select all

Updated in a Later post
Last edited by truthSeeker on Wed Aug 15, 2012 1:13 am, 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 Aug 10, 2012 8:59 am

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!

truthSeeker
New poster
Posts: 5
Joined: Thu Aug 09, 2012 11:09 pm

Re: 11340 - Newspaper

Post by truthSeeker » Sat Aug 11, 2012 1:52 am

I guess this input should give the following output :

Code: Select all

3.74$
3.74$
and this is exactly what my code prints !!!
Attachments
io.PNG
Print screen of the code's output
io.PNG (22.25 KiB) Viewed 1993 times

Post Reply

Return to “Volume 113 (11300-11399)”