Aman & Mr.Sharma[hackerearth]

Aman & Mr.Sharma

If you use perimeter = 2(22/7)*radius <= horlics*100 formula then the resedual floating point will cause error and might cause some deviation in the number of toffee in final calculation in big input so instead use  perimeter = 44*radius <= horlics*700.

import java.util.*;

class TestClass {
public static void main(String args[] ) throws Exception {

Scanner s = new Scanner(System.in);
int day = s.nextInt();
int toffee = 0;
for(int i = 0; i<day; i++){
long radius = s.nextLong();
long horlics = s.nextLong();
long distC = 44*radius;
long distH = 700*horlics;
if(distC <= distH){
toffee++;
}
}
System.out.println(toffee);


}
}

Book of Potion making [hackerearth]

Problem: Book of Potion-making

 

<!– HTML generated using hilite.me –>

/* Ketan D. Ramteke
*/
import java.util.*;

class TestClass {
public static void main(String args[] ) throws Exception {

// Write your code here
Scanner s = new Scanner(System.in);
String number = s.nextLine();
int addition = 0;
if(number.length() == 10){
char[] numArray = number.toCharArray();
for(int i = 0; i < 10; i++){
addition += Character.getNumericValue(numArray[i])*(i+1);
//System.out.println(addition);
}
if(addition % 11 == 0){
System.out.println("Legal ISBN");
}
else{
System.out.println("Illegal ISBN");
}
}
else{
System.out.println("Illegal ISBN");
}

}
}