problem link:
Discuss: this is simply implementation problem.no tricky part in this problem.just check value of n in ascending order in a while loop and add in any double variable and last of all just use ceil function it will be okay
try yourself before see the code
#include<bits/stdc++.h>
using namespace std;
int main()
{
// freopen("input.txt","r",stdin);
// freopen("out.txt","w",stdout);
long long n,i,j,cnt,t,k,m,flag,tax;
double sum;
cin >>t;
for(k=1;k<=t;k++)
{
flag=1;
cin >>n;
printf("Case %lld: ",k);
sum=0;
n-=180000;
if(n>0)
{
flag=0;
while(1)
{
if(n<=300000)
{
sum+=(double)n*.10;
break;
}
else if(n<=700000)
{
m=n-300000;
n-=m;
sum+=(double)m*.15;
}
else if(n<=1000000)
{
m=n-700000;
n-=m;
sum+=(double)m*.20;
}
else if(n>1000000)
{
m=n-1000000;
n-=m;
sum+=double(m)*.25;
}
}
}
if(flag==1)
cout <<0<<endl;
else
{
tax=ceil(sum);
if(tax>=0&&tax<2000)
cout <<2000<<endl;
else
cout <<tax<<endl;
}
}
return 0;
}
Discuss: this is simply implementation problem.no tricky part in this problem.just check value of n in ascending order in a while loop and add in any double variable and last of all just use ceil function it will be okay
try yourself before see the code
#include<bits/stdc++.h>
using namespace std;
int main()
{
// freopen("input.txt","r",stdin);
// freopen("out.txt","w",stdout);
long long n,i,j,cnt,t,k,m,flag,tax;
double sum;
cin >>t;
for(k=1;k<=t;k++)
{
flag=1;
cin >>n;
printf("Case %lld: ",k);
sum=0;
n-=180000;
if(n>0)
{
flag=0;
while(1)
{
if(n<=300000)
{
sum+=(double)n*.10;
break;
}
else if(n<=700000)
{
m=n-300000;
n-=m;
sum+=(double)m*.15;
}
else if(n<=1000000)
{
m=n-700000;
n-=m;
sum+=(double)m*.20;
}
else if(n>1000000)
{
m=n-1000000;
n-=m;
sum+=double(m)*.25;
}
}
}
if(flag==1)
cout <<0<<endl;
else
{
tax=ceil(sum);
if(tax>=0&&tax<2000)
cout <<2000<<endl;
else
cout <<tax<<endl;
}
}
return 0;
}
No comments:
Post a Comment