Skip to content

Commit 41d7c05

Browse files
authoredJun 10, 2024··
Create height_checker.cpp
1 parent 86c7987 commit 41d7c05

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
 
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
class Solution {
5+
public:
6+
int heightChecker(vector<int>& heights) {
7+
vector<int>v(heights);
8+
int count=0;
9+
sort(v.begin(),v.end());
10+
for(int i=0;i<heights.size();i++){
11+
if(height[i]!=v[i]){
12+
count++;
13+
}
14+
}
15+
return count;
16+
}
17+
};
18+
19+
int main() {
20+
int num_students;
21+
22+
23+
cout << "Enter the number of students : ";
24+
cin>>num_students;
25+
26+
vector<int> heights(num_students);
27+
28+
29+
cout << "Enter the heights of the students : ";
30+
for (int i = 0; i < num_students; ++i) {
31+
cin >> heights[i];
32+
}
33+
34+
Solution s;
35+
int num_changes = s.heightChecker(heights);
36+
37+
cout << "Number of students whose height needs to be adjusted: " << num_changes << endl;
38+
39+
return 0;
40+
}

0 commit comments

Comments
 (0)
Please sign in to comment.