-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDota.java
More file actions
35 lines (35 loc) · 786 Bytes
/
Dota.java
File metadata and controls
35 lines (35 loc) · 786 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
import java.util.*;
import java.util.LinkedList;
class Dota
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
String s=in.nextLine().trim();
if(s.length()<1||s.length()>10000||!s.matches("[RD]+"))
{
System.out.println("Invalid input");
return;
}
Queue<Integer> r=new LinkedList<>();
Queue<Integer> d=new LinkedList<>();
int n=s.length();
for(int i=0;i<n;i++)
{
if(s.charAt(i)=='R')
r.add(i);
else
d.add(i);
}
while(!r.isEmpty() && !d.isEmpty())
{
int ri=r.poll();
int di=d.poll();
if(ri<di)
r.add(ri+n);
else
d.add(di+n);
}
System.out.println(r.isEmpty()? "Dire":"Radiant");
}
}