-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAvoid Fixed Points.cpp
48 lines (29 loc) · 957 Bytes
/
Avoid Fixed Points.cpp
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
#include <iostream>
using namespace std;
int main() {
//test is a variable to take number of input test cases
int test;
//taking input using cin extraction operator
cin>>test;
//other variables that would be used during logic building and calculations
int n,x,k;
//here goes our while loop
while(test--){
//initializing k to 0 on each test case
k=0;
//input n ie the sizee of array
cin>>n;
//allocating an array of size n
int a[n];
//here goes initializing and calculation
for(int i=0;i<n;i++){
//input the elements of the array one by one
cin>>a[i];
x=1+k+i;
(x==a[i]?k++:0);
}
//printing up the result
cout<<k<<endl;
}
return 0;
}