-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeamwork.java
More file actions
35 lines (34 loc) · 820 Bytes
/
Teamwork.java
File metadata and controls
35 lines (34 loc) · 820 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
/*
* Timus OJ - 1581
* Teamwork
*/
import java.io.*;
import java.util.*;
public class Teamwork {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(f.readLine());
StringTokenizer st = new StringTokenizer(f.readLine());
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = Integer.parseInt(st.nextToken());
}
int current = 1;
int i = 1;
int j = 0;
while (i < n) {
if (nums[i] == nums[j]) {
current++;
}
else {
System.out.print(current + " " + nums[j] + " ");
current = 1;
j = i;
}
i++;
}
System.out.println(current + " " + nums[j] + " ");
f.close();
System.exit(0);
}
}