chillurbrain

2. Такси

May 21st, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.         int a = sc.nextInt();
  8.         int b = sc.nextInt();
  9.         int c = sc.nextInt();
  10.         int d = sc.nextInt();
  11.         int ans = a;
  12.         if (a >= c) {
  13.             System.out.println(a);
  14.             return;
  15.         }
  16.         while (true) {
  17.             if (a + b <= c) {
  18.                 ans = a + b;
  19.                 a += b;
  20.             } else {
  21.                 ans = c;
  22.                 break;
  23.             }
  24.             if (c - d >= a) {
  25.                 ans = c - d;
  26.                 c -= d;
  27.             } else {
  28.                 ans = a;
  29.                 break;
  30.             }
  31.         }
  32.         System.out.println(ans);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment