Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- using namespace std;
- int main()
- {
- ifstream cin("bac.txt");
- int a, b, c, nr=2, nrmax=0;
- cin>>a>>b; //retinem primii 2 termeni din sir
- while(cin>>c)
- {
- if(a!=b && a!=c && b!=c) //daca elementele consecutive fac parte din secventa
- nr++; // lungimea creste
- else
- { if( nr>nrmax) //actualizam lungimea maxima
- nrmax=nr;
- nr=2; //resetam secventa
- }
- a=b; //pregatim urmatorul triplet
- b=c;
- }
- if(nr>nrmax) // tratam cazul in care ultimele 3 elemente fac parte dintr-o secventa
- nrmax=nr;
- cout<<nrmax;
- }
- /* O(n), n este numarul de numere citite.
- Are 5 variabile intregi.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement