Tip : Hi there . Read the problem Statement?? How's it ? Easy . Isn't it ? A little bit logical. How to place the comma ',' . Think yourself please . Not Found? Lets go . a comma ',' after a thousands. So, to find out thousands divide the summation by 1000.0 ( as summation is is a floating point number ) . If summation is 1111 to find the place of comma divide summation by 1000 and then print result, a comma ',' and then print the remainder . That will be the answer .
Is there anything fishy left?? Yes.
What if the sum is greater than 999999 ? Find it out . Its upto you. As I did . If you fail then go down .
Code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
double d, sum;
int j=0;
scanf("%d",&t);
while(t--)
{
sum = 0;
for(int i=0; i<12; i++)
{
scanf("%lf",&d);
sum = sum + d;
}
double avg = sum/12.00;
printf("%d $",++j);
if(avg<=999999999999999.0 && avg>999999999999.0)
{ int a = avg/1000000000000.0; printf("%d,",a); avg = fmod(avg,1000000000000.0);}
if(avg<=999999999999.0 && avg>999999999.0)
{ int a = avg/1000000000.0; printf("%d,",a); avg = fmod(avg,100000000.0);}
if(avg<=999999999.0 && avg>999999.0)
{ int a = avg/1000000.0; printf("%d,",a); avg = fmod(avg,1000000.0);}
if(avg<=999999.0 && avg>999.0)
{ int a = avg/1000.0; printf("%d,",a); avg = fmod(avg,1000.0);}
printf("%.2lf\n",avg);
}
return 0;
}
=> Questions ? Leave a Comment .
This comment has been removed by the author.
ReplyDeleteThis article is very interested UVa - 11945 ( Financial Management Solution ) investment tips
ReplyDelete