Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- public class Krebota{
- public static void main(String[] args) {
- getHeliumFraction(6, 6, 1, 3, 2, 2, 3);
- }
- public static void getHeliumFraction(int n, int... s){
- boolean possible = true;
- int[] balloons = new int[n];
- int[] cannisters = new int[n];
- for(int i = 1; i <= n ; i++ ){
- balloons[i - 1] = i;
- System.out.println(i);
- }
- for(int i = 0 ; i < s.length ; i ++){
- cannisters [i] = s[i];
- }
- Arrays.sort(cannisters);
- if (cannisters.length == balloons.length ){
- double currNum = 1;
- int numerator = 0;
- int denominator = 1;
- for(int i = 0 ; i < cannisters.length ; i++) {
- int a = cannisters[i];
- if(a > balloons[i]){
- System.out.println("impossible");
- possible = false;
- break;
- }
- double fraction = a/balloons[i] ;
- if(fraction <= currNum){
- currNum = fraction;
- denominator = balloons[i] ;
- numerator = a;
- }
- }
- if(possible){
- System.out.println("The fraction needed is " + numerator + "/" + denominator);
- }
- }else{
- System.out.println("The number of cannisters must be same as that of balloons.");
- }
- }
- }
Add Comment
Please, Sign In to add comment