Page 1 of 1
11945 - Financial Management
Posted: Fri Apr 08, 2011 2:43 am
by mostafa_angel
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;
}
Re: 11945 - Financial Management
Posted: Fri Apr 08, 2011 8:50 pm
by stencel
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.
Re: 11945 - Financial Management
Posted: Sun Apr 10, 2011 12:53 am
by mostafa_angel
I don't understand it !
how I can Do it !?
thank U for replay !

Re: 11945 - Financial Management
Posted: Sun Apr 10, 2011 2:08 am
by stencel
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.
Re: 11945 - Financial Management
Posted: Fri Jul 15, 2011 1:10 pm
by plamplam
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
Re: 11945 - Financial Management
Posted: Sat Nov 17, 2012 10:39 pm
by Muftee_Ruet
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
Re: 11945 - Financial Management
Posted: Fri May 24, 2013 2:31 am
by ahsan101
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
Re: 11945 - Financial Management
Posted: Sat May 25, 2013 2:42 am
by brianfry713
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
uva 11945
Posted: Tue Oct 22, 2013 10:53 am
by walking_hell
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;
}
Re: uva 11945
Posted: Tue Oct 22, 2013 10:08 pm
by brianfry713
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:
Re: 11945 - Financial Management
Posted: Tue Dec 31, 2013 12:16 pm
by uDebug
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