Created
June 10, 2018 10:12
-
-
Save invatainfo/fc9742cebde225ae67dec1e341a7c5bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <string.h> | |
using namespace std; | |
int main() { | |
ifstream f("bac.txt"); | |
long prima_aparitie[10], nr = 0, lungime[10], maxim = 0; | |
int a; | |
// punem 0 in vector byte cu byte (mai rapid decat un for) | |
memset(prima_aparitie, 0, sizeof(long) * 10); | |
while (f >> a) { | |
nr++; | |
if (prima_aparitie[a] == 0) { | |
prima_aparitie[a] = nr; | |
} else { //calculam lungimea sirului de la prima aparitie pana acum | |
lungime[a] = nr - prima_aparitie[a] + 1; | |
if (lungime[a] > maxim) //daca am gasit un nou maxim | |
maxim = lungime[a]; | |
} | |
} | |
int i; | |
cout << maxim << '\n'; | |
for (i = 0; i < 10; i++) { | |
if (lungime[i] == maxim) | |
cout << i << " "; | |
} | |
f.close(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment