-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP121.java
More file actions
33 lines (31 loc) · 1.26 KB
/
P121.java
File metadata and controls
33 lines (31 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package buclesSimples;
import java.util.Scanner;
//accepted
public class P121 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int proporcion = sc.nextInt();
int extra = sc.nextInt();
int chiclesComprados = sc.nextInt();
while (proporcion!=0 || extra!=0 || chiclesComprados!=0){
int chiclesComidos= chiclesComprados;
int envoltoriosRestantes=chiclesComprados;
if( extra==0 || chiclesComprados==0){
System.out.println(chiclesComidos + " " + envoltoriosRestantes);
}
else if(extra>=proporcion && chiclesComprados>=proporcion){
System.out.println("RUINA");
}else {
while (envoltoriosRestantes >= proporcion) {
int chiclesRegalados = (envoltoriosRestantes/proporcion)*extra;
chiclesComidos+=chiclesRegalados;
envoltoriosRestantes =chiclesRegalados+(envoltoriosRestantes%proporcion);
}
System.out.println(chiclesComidos + " " + envoltoriosRestantes);
}
proporcion = sc.nextInt();
extra = sc.nextInt();
chiclesComprados = sc.nextInt();
}
}
}