Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- int S(int* a, int indice)
- {
- int i=0, conta=0;
- bool ok=true;
- if(a[0]==-2)
- return -2;
- while(ok) // NELLA VERSIONE CHE MI DAVA PROBLEMI AVEVO SCRITTO while(a[i]!=-2&&ok)
- {
- if(conta<=indice&&a[i]==-2)
- {
- return -2;
- ok=false;
- }
- if(a[i]!=-1)
- i++;
- if(a[i]==-1)
- {
- conta++;
- i++;
- }
- if(conta==indice&&a[i]!=-2)
- {
- return i;
- ok=false;
- }
- }
- }
- main()
- {
- ifstream IN("input");
- ofstream OUT("output");
- if(IN && OUT)
- {
- int X[100];
- IN>>X[0];
- for(int i=1; i<100 && X[i-1]!=-2; i++)
- {IN>>X[i];}
- int a;
- IN>>a;
- int b=S(X,a); // funzione da fare
- if(b==-2)
- OUT<<"sottosequenza "<<a<<" non presente"<<endl;
- else
- OUT<<"inizio sottosequenza "<<a<<" indice="<<b<<endl;
- OUT<<"fine"<<endl;
- IN.close(); OUT.close();
- }
- else
- cout<<"errore con i files";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement