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