-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallindex_x_array.cpp
More file actions
45 lines (41 loc) · 881 Bytes
/
allindex_x_array.cpp
File metadata and controls
45 lines (41 loc) · 881 Bytes
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
#include<iostream>
using namespace std;
int allindex_x_array(int ar[],int size,int x,int *output)
{
if(size==0){
return 0;
}
int smallpart=allindex_x_array(ar+1,size-1,x,output);
for(int i=0;i<smallpart;i++){
output[i]=output[i]+1;
}
if(ar[0]==x){
for(int i=smallpart;i>0;i--){
output[i]=output[i-1];
}
output[0]=0;
return smallpart+1;
}
else{
return smallpart;
}
}
int main(){
int n;
cin>>n;
int *ar=new int [n];
for(int i=0;i<n;i++){
cin>>ar[i];
}
int x;
cout<<"enter number"<<endl;
cin>>x;
int *output=new int[n];
cout<< allindex_x_array(ar,n,x,output)<<endl;
for(int i=0;i<allindex_x_array(ar,n,x,output);i++){
cout<<output[i]<<" ";
}
cout<<endl;
delete ar;
delete output;
}