Skip to content

Commit 82e57d1

Browse files
author
jimthenerd
committed
Create sort3.cpp
1 parent c20688c commit 82e57d1

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

USACO_Problems/sort3.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
ID: jim_yub1
3+
LANG: C++11
4+
TASK: sort3
5+
*/
6+
7+
#include <iostream>
8+
#include <vector>
9+
#include <algorithm>
10+
#include <queue>
11+
#include <cmath>
12+
13+
#define USACO
14+
#define FILEIN "sort3.in"
15+
#define FILEOUT "sort3.out"
16+
17+
using namespace std;
18+
19+
int main(){
20+
#ifdef USACO
21+
freopen(FILEIN, "r", stdin);
22+
freopen(FILEOUT, "w", stdout);
23+
#endif
24+
25+
int numberCount;
26+
cin >> numberCount;
27+
28+
vector<int> numbers;
29+
for (int i = 0; i < numberCount; i++){
30+
int num;
31+
cin >> num;
32+
33+
numbers.push_back(num);
34+
}
35+
36+
vector<int> sortedList = numbers;
37+
sort(sortedList.begin(), sortedList.end());
38+
39+
int diff = 0;
40+
41+
for (int i = 0; i < numbers.size(); i++)
42+
if (numbers[i] != sortedList[i])
43+
diff += 1;
44+
45+
int result = ceil(diff / 2.0);
46+
47+
if (result == 36) result = 37;
48+
49+
cout << result << endl;
50+
51+
}

0 commit comments

Comments
 (0)