Advertisement
Guest User

ricorsiva

a guest
Sep 30th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int S(int *X, int i){
  5.  
  6.     if(X[0]==-2)
  7.     return -2;
  8.    
  9.     if(X[0]==-1)
  10.     i--;
  11.    
  12.     if(!i){
  13.    
  14.         if(X[1]==-2)
  15.         return -2;
  16.        
  17.         return 1;
  18.     }
  19.    
  20.    
  21.     int r=S(X+1, i);
  22.    
  23.     if(r==-2)
  24.     return -2;
  25.    
  26.     return 1+r;
  27. }
  28.  
  29. int main(){
  30.  
  31.    int X[100];
  32.    cin>>X[0];
  33.    
  34.    for(int i=1; i<100 && X[i-1]!=-2; i++)
  35.    cin>>X[i];
  36.    
  37.    int a;
  38.    cin>>a;
  39.    
  40.    int b=S(X,a);
  41.    
  42.    if(b==-2)
  43.      cout<<"sottosequenza "<<a<<" non presente"<<endl;
  44.    else
  45.      cout<<"inizio sottosequenza "<<a<<" indice="<<b<<endl;
  46.  
  47.  
  48.    cout<<"end"<<endl;
  49.    
  50.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement