File tree 1 file changed +40
-0
lines changed
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments