Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4.  
  5. int S(int* a, int indice)
  6. {
  7. int i=0, conta=0;
  8. bool ok=true;
  9. if(a[0]==-2)
  10. return -2;
  11. while(ok) // NELLA VERSIONE CHE MI DAVA PROBLEMI AVEVO SCRITTO while(a[i]!=-2&&ok)
  12. {
  13. if(conta<=indice&&a[i]==-2)
  14. {
  15. return -2;
  16. ok=false;
  17. }
  18. if(a[i]!=-1)
  19. i++;
  20. if(a[i]==-1)
  21. {
  22. conta++;
  23. i++;
  24. }
  25. if(conta==indice&&a[i]!=-2)
  26. {
  27. return i;
  28. ok=false;
  29. }
  30.  
  31. }
  32. }
  33. main()
  34. {
  35. ifstream IN("input");
  36. ofstream OUT("output");
  37. if(IN && OUT)
  38. {
  39. int X[100];
  40. IN>>X[0];
  41. for(int i=1; i<100 && X[i-1]!=-2; i++)
  42. {IN>>X[i];}
  43.  
  44. int a;
  45. IN>>a;
  46. int b=S(X,a); // funzione da fare
  47. if(b==-2)
  48. OUT<<"sottosequenza "<<a<<" non presente"<<endl;
  49. else
  50. OUT<<"inizio sottosequenza "<<a<<" indice="<<b<<endl;
  51.  
  52.  
  53. OUT<<"fine"<<endl;
  54. IN.close(); OUT.close();
  55. }
  56. else
  57. cout<<"errore con i files";
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement