-
Notifications
You must be signed in to change notification settings - Fork 0
/
usaco.java
87 lines (79 loc) · 1.68 KB
/
usaco.java
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
ID: mancgup2
LANG: JAVA
TASK: sort3
*/
import java.io.*;
import java.util.*;
/**
* Created with IntelliJ IDEA.
* User: Manchit Gupta
* Date: 10/7/12
* Time: 8:37 PM
* To change this template use File | Settings | File Templates.
*/
public class sort3 {
public void solve() throws IOException {
int n = nextInt();
int []a = new int[n];
for(int i=0;i<a.length;i++){
a[i] = nextInt();
}
int cnt = 0;
for(int i=a.length-1;i>=0;i--){
int max = a[i];
int loc = -1;
for(int j=0;j<i;j++){
if(a[j]>max){
max = a[j];
loc = j;
}
}
if(loc!=-1){
int temp = a[i];
a[i] = a[loc];
a[loc] = temp;
cnt ++;
}
}
out.println(cnt);
}
BufferedReader in;
StringTokenizer tokenizer;
PrintWriter out;
public void run() {
try {
// in = new BufferedReader(new InputStreamReader(System.in));
// out = new PrintWriter(System.out);
in = new BufferedReader(new FileReader("sort3.in"));
out = new PrintWriter(new BufferedWriter(new FileWriter("sort3.out")));
tokenizer = null;
solve();
in.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
String next() throws IOException {
return nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(in.readLine());
}
return tokenizer.nextToken();
}
public static void main(String[] args) {
new sort3().run();
}
}