-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBatalie cosmica.java
More file actions
37 lines (36 loc) · 981 Bytes
/
Batalie cosmica.java
File metadata and controls
37 lines (36 loc) · 981 Bytes
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
34
35
36
37
import java.util.*;
public class Eccpr{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
ArrayList<Nave>list = new ArrayList<>();
Nave nava = new Nave(sc.nextInt(),sc.nextInt());
int n = sc.nextInt();
for(int i=0;i<n;i++){
list.add(new Nave(sc.nextInt(),sc.nextInt()));
nava.atac(list.get(i));
}
System.out.println(nava.scor);
}
}
public class Nave{
int first,second,life;
static int scor=0;
Nave(int first, int second){
this.first=first;
this.second=second;
this.life=first;
}
void atac(Nave p){
while(p.first>=0||this.first>=0){
this.first-=p.second;
if(this.first<0) break;
p.first-=this.second;
}
if(p.first<0){
scor++;
}
if(this.first<0){
this.first=this.life;
}
}
}