Advertisement
Matteo_Pillon

Untitled

Mar 26th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int S (int *A, int n){
  5.     int count=0;
  6.     for(int i=0; i<400 && A[i]!=-2;i++){
  7.         if(A[i]==-1&&i==0){
  8.             return -2;
  9.         }
  10.         else if (A[i]==-1 && A[i+1]!=-2 && count<n){
  11.             count++;
  12.         }
  13.        
  14.         if(count==n){
  15.             return i+1;
  16.         }
  17.     }
  18.     return -2;
  19. }
  20.  
  21. main()
  22. {
  23.     int X[400];
  24.     cin>>X[0];
  25.     for(int i=1; i<400 && X[i-1]!=-2; i++){
  26.        cin >>X[i];
  27.     }
  28.    
  29.     int n;
  30.     cin>>n;
  31.     cout<<"start"<<endl;
  32.     int b=S(X,n); // da fare
  33.     if(b==-2){
  34.          cout<<"sottosequenza "<<n<<" non presente"<<endl;
  35.     }
  36.     else{
  37.          cout<<"inizio sottosequenza "<<n<<" indice="<<b<<endl;
  38.     }
  39.     cout<<"end"<<endl;
  40.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement