11945 - Financial Management

All about problems in Volume 119. 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
mostafa_angel
New poster
Posts: 23
Joined: Sun Oct 04, 2009 12:03 pm

11945 - Financial Management

Post by mostafa_angel » Fri Apr 08, 2011 2:43 am

I think this Problem is so easy but I don't know Why I Got WA ?
Please Help :)
my code :

Code: Select all

#include <iostream>
#include <cmath>

using namespace std;
typedef long long int ll;

ll expand(double a)
{
	ll res = (ll)(a*100);
	return res;
}

int main()
{
	int n;
	cin >> n;
	for(int pp =1 ; pp <= n ; pp++)
	{
		double sum = 0.0;
		double tmp;
		for(int i = 0 ; i < 12 ; i++)
		{
			cin >> tmp;
			sum+= tmp;
		}
		double mean = sum/12;
		cout << pp << " $";
		int penny;
		ll t = mean*100;
		//ll t = 1203443200;
		penny = t%100;
		t/=100;
		int to[100] = {0};
		int cnt = 0;
		while(t / 1000 > 0)
		{
			to[cnt++] = t%1000;
			t/=1000;
		}
		cout << t;
		for(int i = 0 ; i < cnt ; i ++)
			cout << "," << to[cnt-1-i];
		cout <<".";
		if(penny == 0)
			cout << "00";
		else
			cout << penny;
		cout << endl;
	}
	
	return 0;
}

stencel
New poster
Posts: 8
Joined: Tue Oct 19, 2010 10:21 am

Re: 11945 - Financial Management

Post by stencel » Fri Apr 08, 2011 8:50 pm

It looks like your problem is the division by 12 which does not round to the nearest penny.

I am not sure it is the only problem, but fully debugging your program will kill all your fun.

mostafa_angel
New poster
Posts: 23
Joined: Sun Oct 04, 2009 12:03 pm

Re: 11945 - Financial Management

Post by mostafa_angel » Sun Apr 10, 2011 12:53 am

I don't understand it !
how I can Do it !?
thank U for replay ! :)

stencel
New poster
Posts: 8
Joined: Tue Oct 19, 2010 10:21 am

Re: 11945 - Financial Management

Post by stencel » Sun Apr 10, 2011 2:08 am

mostafa_angel wrote:I don't understand it !
how I can Do it !?
thank U for replay ! :)
When the sum is 6 pennies, you print 0 while after rounding half a penny to the nearest penny you should get 1 as the answer.

User avatar
plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

Re: 11945 - Financial Management

Post by plamplam » Fri Jul 15, 2011 1:10 pm

Try this

Code: Select all

8

100.00 
489.12 
12454.12 
1234.10 
823.05 
109.20 
5.27 
1542.25 
839.18 
83.99 
1295.01 
1.75

100000.00
489120.00
12454120.00
1234100.00
823050.00
109200.00
5270.00
1542250.00
839180.00
83990.00
1295010.00
1750.00

0.00
0.50
0.50
0.50
0.00
0.00
0.50
0.00
0.50
0.00
0.00
0.50

0.00
0.50
0.50
0.50
0.00
0.00
0.50
0.00
0.50
0.00
0.00
0.48

0.00
0.50
0.50
0.50
0.00
0.00
0.50
0.00
0.50
0.00
0.00
0.47

0.00
0.01
0.01
0.01
0.00
0.00
0.01
0.00
0.01
0.00
0.00
0.01

0.00
0.01
0.01
0.01
0.00
0.00
0.01
0.00
0.01
0.00
0.00
0.00

0.01
0.01
0.01
0.01
0.00
0.00
0.01
0.00
0.01
0.00
0.00
0.01

Code: Select all

1 $1,581.42
2 $1581,420.00
3 $0.17
4 $0.17
5 $0.16
6 $0.01
7 $0.00
8 $0.01
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

Muftee_Ruet
New poster
Posts: 10
Joined: Fri Sep 16, 2011 6:36 am

Re: 11945 - Financial Management

Post by Muftee_Ruet » Sat Nov 17, 2012 10:39 pm

My Accepted code gives the following output.

Input

Code: Select all

8

100.00 
489.12 
12454.12 
1234.10 
823.05 
109.20 
5.27 
1542.25 
839.18 
83.99 
1295.01 
1.75

100000.00
489120.00
12454120.00
1234100.00
823050.00
109200.00
5270.00
1542250.00
839180.00
83990.00
1295010.00
1750.00

0.00
0.50
0.50
0.50
0.00
0.00
0.50
0.00
0.50
0.00
0.00
0.50

0.00
0.50
0.50
0.50
0.00
0.00
0.50
0.00
0.50
0.00
0.00
0.48

0.00
0.50
0.50
0.50
0.00
0.00
0.50
0.00
0.50
0.00
0.00
0.47

0.00
0.01
0.01
0.01
0.00
0.00
0.01
0.00
0.01
0.00
0.00
0.01

0.00
0.01
0.01
0.01
0.00
0.00
0.01
0.00
0.01
0.00
0.00
0.00

0.01
0.01
0.01
0.01
0.00
0.00
0.01
0.00
0.01
0.00
0.00
0.01
Output

Code: Select all

1 $1,581.42
2 $1581,420.00
3 $0.25
4 $0.25
5 $0.25
6 $0.01
7 $0.00
8 $0.01

ahsan101
New poster
Posts: 1
Joined: Fri May 24, 2013 1:16 am

Re: 11945 - Financial Management

Post by ahsan101 » Fri May 24, 2013 2:31 am

Code: Select all

#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string.h>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main()
{
   int t;
   cin>>t;
   int c=1;
   while(t--)
   {
       double r=0,in;
       for(int i=0;i<12;i++)
       {
           cin>>in;
           r+=in;
       }
       double avg=r/12;
       if(r>999.00)
       {
          // avg=(long)(r/1000);
           cout<<c++<<" $"<<(long)(avg/1000.0)<<",";
           printf("%.2lf\n",round(fmod(avg,1000.0)*100)/100);
       }
       else printf("%d $%.2lf\n",c++,round(avg*100)/100);
   }
}
Whats wrong with my code ??? keep getting WA

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

Re: 11945 - Financial Management

Post by brianfry713 » Sat May 25, 2013 2:42 am

Input:

Code: Select all

1
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
999.99
AC output:
1 $83.33
Check input and AC output for thousands of problems on uDebug!

walking_hell
New poster
Posts: 14
Joined: Tue Sep 24, 2013 4:35 pm

uva 11945

Post by walking_hell » Tue Oct 22, 2013 10:53 am

GETTING WA... CANT FIND MY BUG

Code: Select all

#include<stdio.h>
#include<string.h>
int main()
{
    double nums,avg;
    int count,test,ll,len;
    char arr[1000];
    while(scanf("%d",&test)==1)
    {
        for(count=1;count<=test;count++)
        {
            avg=0;
            for(ll=0;ll<12;ll++)
            {
                scanf("%lf",&nums);
                avg=avg+nums;

            }
            avg=avg/12.0;
            sprintf(arr,"%.2lf",avg);
            len=strlen(arr);
            printf("%d $",count);
            for(ll=0;ll<len;ll++)
            {
                if(ll==len-6)
                printf(",%c",arr[ll]);
                else
                printf("%c",arr[ll]);

            }
            printf("\n");
        }
    }
    return 0;
}

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

Re: uva 11945

Post by brianfry713 » Tue Oct 22, 2013 10:08 pm

Try Input:

Code: Select all

1
999.99
999.99
999.99
999.99
999.99
999.99
999.99
999.99
999.99
999.99
999.99
999.99
AC output:

Code: Select all

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

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11945 - Financial Management

Post by uDebug » Tue Dec 31, 2013 12:16 pm

Muftee_Ruet wrote:My Accepted code gives the following output.
Output

Code: Select all

1 $1,581.42
2 $1581,420.00
3 $0.25
4 $0.25
5 $0.25
6 $0.01
7 $0.00
8 $0.01
I was a bit confused when I saw this, since in my mind $1581,420.00 should've been $1,581,420.00. (Note the addition of the comma between 1 and 5). Turns out that the comma is indeed required and that this is the AC output for the input given by plamplam .

Code: Select all

1 $1,581.42
2 $1,581,420.00
3 $0.25
4 $0.25
5 $0.25
6 $0.01
7 $0.00
8 $0.01
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Post Reply

Return to “Volume 119 (11900-11999)”