Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int S(int *X, int i){
- if(X[0]==-2)
- return -2;
- if(X[0]==-1)
- i--;
- if(!i){
- if(X[1]==-2)
- return -2;
- return 1;
- }
- int r=S(X+1, i);
- if(r==-2)
- return -2;
- return 1+r;
- }
- int main(){
- int X[100];
- cin>>X[0];
- for(int i=1; i<100 && X[i-1]!=-2; i++)
- cin>>X[i];
- int a;
- cin>>a;
- int b=S(X,a);
- if(b==-2)
- cout<<"sottosequenza "<<a<<" non presente"<<endl;
- else
- cout<<"inizio sottosequenza "<<a<<" indice="<<b<<endl;
- cout<<"end"<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement