Page 5 of 11

Re: 11340 - Newspaper

Posted: Tue Jan 24, 2012 8:53 pm
by arunanshu
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;
    }

Re: 11340 - Newspaper

Posted: Wed Jan 25, 2012 2:42 am
by brianfry713
This fails for the sample input.

Re: 11340 - Newspaper

Posted: Wed Mar 28, 2012 7:35 pm
by Achilies_Saiful_Buet
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....

Re: 11340 - Newspaper

Posted: Thu Mar 29, 2012 1:09 am
by brianfry713
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.

Re: 11340 - Newspaper

Posted: Thu Mar 29, 2012 8:25 am
by Achilies_Saiful_Buet
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.....

Re: 11340 - Newspaper

Posted: Sat May 26, 2012 11:26 am
by sith
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

Re: 11340 - Newspaper

Posted: Tue May 29, 2012 4:55 pm
by SyFyKid
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) {
        }
    }
}

Re: 11340 - Newspaper

Posted: Tue Jun 05, 2012 1:52 pm
by sith
Thanks a lot
It works!!!

Re: 11340 - Newspaper

Posted: Tue Jun 05, 2012 7:10 pm
by mahade hasan
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]

Re: 11340 - Newspaper

Posted: Tue Jun 05, 2012 9:30 pm
by brianfry713
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.

getting WA for 11340, help plz

Posted: Wed Jul 04, 2012 12:21 am
by esharif

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;
}

Re: getting WA for 11340, help plz

Posted: Fri Jul 06, 2012 1:48 am
by brianfry713
printf("%.2lf$\n", result);

A double is %lf, a float is %f

Re: 11340 - Newspaper

Posted: Thu Aug 09, 2012 11:21 pm
by truthSeeker
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

Re: 11340 - Newspaper

Posted: Fri Aug 10, 2012 8:59 am
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: Sat Aug 11, 2012 1:52 am
by truthSeeker
I guess this input should give the following output :

Code: Select all

3.74$
3.74$
and this is exactly what my code prints !!!