ZOJ Problem Set - 1005 - Jugs

https://www.cnblogs.com/devymex/archive/2010/08/04/1792288.html

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int A;
        int B;
        int goal;
        
        int nowA, nowB;
        while(input.hasNext()) {
            A = input.nextInt();
            B = input.nextInt();
            goal = input.nextInt();
            nowA = 0;
            nowB = 0;
            
            while(nowB != goal) {
                if(nowA == 0) {
                    System.out.println("fill A");
                    nowA = A;
                }
                
                if(nowB == B) {
                    System.out.println("empty B");
                    nowB = 0;
                }
                
                nowB += nowA;
                nowA = 0;
                if(nowB > B) {
                    nowA = nowB - B;
                    nowB = B;
                }
                System.out.println("pour A B");
            }
            System.out.println("success");
        }
    }
}

 

posted on 2018-02-03 22:20  NEU-2015  阅读(76)  评论(0编辑  收藏  举报

导航