Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class aniIsDrunk160815 {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int cabins = Integer.parseInt(scan.nextLine());
- String command = scan.nextLine();
- int currentPos = 0;
- int count = 0;
- while(!(command.equals("Found a free one!"))){
- int steps = Integer.parseInt(command);
- int oldPos = currentPos;
- currentPos = (currentPos + steps) % cabins;
- int diff = currentPos - oldPos;
- count = count + Math.abs(diff);
- if(diff > 0){
- System.out.printf("Go %d steps to the right, Ani%n",diff);
- }else if(diff <0){
- System.out.printf("Go %d steps to the left, Ani%n", Math.abs(diff));
- }else{
- break;
- }
- command = scan.nextLine();
- }
- System.out.printf("Moved a total of %d steps.",count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement