Problem Link–>https://www.codechef.com/problems/APPROX
My Solution–>https://www.codechef.com/viewsolution/11605047
After Trying 3-4 Submisions I Looked at SomeOne Code Its Generating Same Output As Mine Code With Different Logic ,Please Help,Thanks in Advance
My code—>
class Approx
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t!=0)
{
int k=sc.nextInt();
BigDecimal a=new BigDecimal("103993.00");
BigDecimal d=new BigDecimal("33102.00");
BigDecimal b=new BigDecimal("0.0");
if(k==0)
System.out.print("3");
else
{
b=a.divide(d,k+2,RoundingMode.HALF_UP);
String s=b.toString();
for(int i=0;i<s.length()-2;i++)
System.out.print(s.charAt(i));
}
System.out.println();
t--;
}
}
}
I used simple trick and to round off the value to k+2(doesn’t effect answer),and get values till k…