Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Cake1 {
- public static void main(String[] agrs) {
- Scanner scanner = new Scanner(System.in);
- int width = Integer.parseInt(scanner.nextLine());
- int length = Integer.parseInt(scanner.nextLine());
- int allPieces = width * length; //колко парчета торта имаме
- int totalPices = 0; //брои колко парчета сме взели
- int leftPieces = 0; // остатък от парчета
- for (int i = 0; i < allPieces; i++) {
- String pieces = scanner.nextLine();
- if (!pieces.equals("STOP")) {
- totalPices += Integer.valueOf(pieces);
- leftPieces = allPieces - totalPices;
- if (leftPieces < 0) {
- System.out.printf("No more cake left! You need %d pieces more.", Math.abs(leftPieces));
- break;
- }
- } else {
- leftPieces = Math.abs(allPieces - totalPices);
- System.out.printf("%d pieces are left.", leftPieces);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement