12342 - Tax Calculator

All about problems in Volume 123. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

uvasarker
Learning poster
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh
Contact:

12342 - Tax Calculator

Post by uvasarker »

I am getting W A.
Please anyone help me.

Code: Select all

/* Removed After AC*/
/* Thanks to Allah*/
Last edited by uvasarker on Thu Jun 07, 2012 6:09 pm, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12342 Tax Calculator

Post by brianfry713 »

Don't use doubles at all in this problem.
Check input and AC output for thousands of problems on uDebug!
mahade hasan
Learning poster
Posts: 87
Joined: Thu Dec 15, 2011 3:08 pm
Location: University of Rajshahi,Bangladesh

Re: 12342 Tax Calculator

Post by mahade hasan »

cut...
Last edited by mahade hasan on Mon Jun 11, 2012 7:01 pm, edited 1 time in total.
we r surrounded by happiness
need eyes to feel it!
uvasarker
Learning poster
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh
Contact:

Re: 12342 Tax Calculator

Post by uvasarker »

Use double for tax calculating and also ceil the value of tax after each tax calculation.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12342 Tax Calculator

Post by brianfry713 »

Don't use doubles at all in this problem.
Check input and AC output for thousands of problems on uDebug!
mahade hasan
Learning poster
Posts: 87
Joined: Thu Dec 15, 2011 3:08 pm
Location: University of Rajshahi,Bangladesh

Re: 12342 Tax Calculator

Post by mahade hasan »

Cut...After AC....
thanks for help man........
Last edited by mahade hasan on Wed Jun 13, 2012 7:41 am, edited 1 time in total.
we r surrounded by happiness
need eyes to feel it!
uvasarker
Learning poster
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh
Contact:

Re: 12342 Tax Calculator

Post by uvasarker »

do look like this

Code: Select all

            double rest=0.0, tmp=0.0, tax=0.0;
            tmp=n-180000;
            n=n-180000;
            if(tmp>300000){
                tax+=0.1*300000.0;
                n=n-300000.0;
                tmp=n;
            }
            else if(n>0){
                tax+=0.1*tmp;
                n=n-300000.0;
                tmp=n;
            }
            tax=(ceil)(tax);
            //printf("tax= %.0lf\n",tax);//tmp1=n-400000;
            if(tmp>400000){
                tax+=0.15*400000.0;
                n=n-400000;
                tmp=n;
            }
            else if(n>0){
                tax+=0.15*tmp;
                n=n-400000;
                tmp=n;
            }
            //printf("tax= %.0lf\n",tax);//tmp2=n-300000;
            tax=(ceil)(tax);

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

Re: 12342 Tax Calculator

Post by brianfry713 »

Don't use doubles at all in this problem.
Check input and AC output for thousands of problems on uDebug!
esharif
New poster
Posts: 18
Joined: Sun Jun 03, 2012 11:56 pm

Why WA 12342. help help....

Post by esharif »

I'm getting continuously WA, But why, help me please..

Code: Select all

#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include<stdio.h>
#include<stdlib.h>

int main()
{
	long int t, income, res, i, temp, flag;
	double tax;
	while(scanf("%ld",&t)==1)
	{
		for(i=1;i<=t;i++)
		{
			tax=0;
			flag=1;
			scanf("%ld", &income);
			if(income<=180000)
				tax=0;
			else
			{
				income-=180000;
				temp=income-300000;
				if(temp<=0)
				{
					tax=(ceil)(income*10/100);
					flag=0;
					if(tax<2000)
						tax=2000;
				}
				else if(income>0 && flag!=0)
				{
					tax+=(ceil)(300000*10/100);
					income-=300000;
				}

                temp=income-400000;
                if(temp<=0 && flag!=0)
                {
                    tax+=(ceil)(income*15/100);
                    flag=0;
                }
                else if(income>0 && flag!=0)
				{
                    tax+=(ceil)(400000*15/100);
                    income-=400000;
                }

                temp=income-300000;
                if(temp<=0 && flag!=0)
                {
                    tax+=(ceil)(temp*20/100);
                    flag=0;
                }
                else if(income>0 && flag!=0)
				{
                    tax+=(ceil)(300000*20/100);
                    income-=300000;
                }

                if(income>0 && flag!=0)
                {
                    tax+=(ceil)(income*25/100);
                    flag=0;
                }

            }
            res=(long int)tax;
            printf("%ld\n", res);
        }
    }
	return 0;
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Why WA 12342. help help....

Post by brianfry713 »

Don't use doubles in this problem.
Check input and AC output for thousands of problems on uDebug!
naam nai
New poster
Posts: 1
Joined: Mon Aug 27, 2012 9:20 am

Re: 12342 Tax Calculator

Post by naam nai »

Getting WA for this code:


#include <stdio.h>
#include <math.h>

int main()
{
int i,n,money,check;
double tax,a;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
check=tax=0;
scanf("%d",&money);
if(money-180000>0)
{
money=money-180000;
if(money-300000<=0)
{
a=((double)(money*10)/100);
a=ceil(a);
tax=tax+a;
}
else
{
a=((double)(300000*10)/100);
a=ceil(a);
tax=tax+a;
money=money-300000;
if(money-400000<=0)
{
a=((double)(money*15)/100);
a=ceil(a);
tax=tax+a;
}
else
{
a=((double)(400000*15)/100);
a=ceil(a);
tax=tax+a;
money=money-400000;
if(money-300000<=0)
{
a=((double)(money*20)/100);
a=ceil(a);
tax=tax+a;
}
else
{
a=((double)(300000*20)/100);
a=ceil(a);
tax=tax+a;
money=money-300000;
if(money>0)
{
a=((double)(money*25)/100);
a=ceil(a);
tax=tax+a;
}
}
}
}
}
else
{
printf("Case %d: %.0lf\n",i,tax);
check++;
}
if(check==0)
{
if(tax>0 && tax<=2000)
{
tax=2000;
printf("Case %d: %.0lf\n",i,tax);
}
else printf("Case %d: %.0lf\n",i,tax);
}
}
return 0;
}
:-?
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12342 Tax Calculator

Post by brianfry713 »

Don't use doubles at all in this problem.
Check input and AC output for thousands of problems on uDebug!
alamin.opu10
New poster
Posts: 1
Joined: Fri Mar 08, 2013 1:49 am

Re: 12342 Tax Calculator

Post by alamin.opu10 »

I am getting WA. can anyone help me?

Code: Select all

#include <stdio.h>
#include <math.h>

int percent(long long ammount,int pcnt){
    int result=0;
    result = ceil((float)(ammount*pcnt)/100);
    return result;
}

int tax_calculator(long long ammount){
    int result=0;
    if(ammount>180000){
        ammount = ammount-180000;
        if(ammount>=300000){
            result = percent(300000,10);
             //printf("res: %d\n",result);
            ammount = ammount - 300000;
            if(ammount>=400000){
                result+= percent(400000,15);
                 //printf("res: %d\n",result);
                ammount = ammount-400000;
                if(ammount>=300000){
                    result+= percent(300000,20);
                     //printf("res: %d\n",result);
                    ammount = ammount-300000;
                    if(ammount>0){
                        result+= percent(ammount,25);
                        //printf("res: %d\n",result);
                    }
                }else{
                    result+= percent(ammount,20);
                    //printf("res: %d\n",result);
                    return result;
                }
            }else{
                result+= percent(ammount,15);
                //printf("res: %d\n",result);
                return result;
            }
        }else{
            result+= percent(ammount,10);
            //printf("res: %d\n",result);
            return result;
        }
    }
    else{
        return 0;
    }
    return result;
}
int main(){
    int cases, caseno=0,result=0;
    long long ammount;
    scanf("%d",&cases);
    while(cases--){
        scanf("%lld",&ammount);
        result = tax_calculator(ammount);
        if(result<2000 && result!=0){
            result=2000;
        }
        printf("Case %d: %d\n",++caseno,result);
    }
    return 0;
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12342 Tax Calculator

Post by brianfry713 »

Don't use floating point at all in this problem.
Check input and AC output for thousands of problems on uDebug!
B_sayem
New poster
Posts: 7
Joined: Wed Dec 11, 2013 7:57 pm

Re: 12342 Tax Calculator

Post by B_sayem »

whats wrong with my program and why i don't use floating point??

Code: Select all

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{
    unsigned long long int n,amount,check=1,tax;
    //float tax;

    cin>>n;
    while(n>0)
    {
        tax=0;
        cin>>amount;
        if(amount<=180000)
        {
            tax=0;
        }
        else
        {
            amount=amount-180000;
            if(amount<=300000)
            {
               
                tax=ceil((amount*10.0)/100);

            }
            else
            {
                tax=(300000*10.0)/100;
                amount=amount-300000;
                if(amount<=400000)
                {
                    tax=ceil(tax+((amount*15.0)/100));
                }
                else
                {
                    tax=(400000*15.0)/100;
                    amount=amount-400000;
                    if(amount<=300000)
                    {
                        tax=ceil(tax+((amount*20.0)/100));
                    }
                    else
                    {
                        tax=(300000*20.0)/100;
                        amount=amount-300000;
                        tax=ceil(tax+((amount*25.0)/100));
                    }
                }
            }



        }
        if(tax>0&&tax<2000)
        {
            tax=2000;
        }

        cout<<"Case "<<check<<": "<<tax<<endl;
        check++;
        n--;
    }
    return 0;
}
Post Reply

Return to “Volume 123 (12300-12399)”