Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- const int MAX_TAILLE = 50000;
- int nbCar;
- bool chaine[MAX_TAILLE];
- struct REP {
- int i, K, L;
- };
- int main()
- {
- scanf("%d\n", &nbCar);
- for (int car = 0; car < nbCar; car++)
- {
- char c;
- scanf("%c", &c);
- getchar();
- chaine[car] = (c == 'a');
- }
- REP best = {0, 1, 1};
- int nbCarSurDeux = nbCar/2;
- for (int taille = 1; taille <= nbCarSurDeux; taille++)
- {
- int longueurRepetee = taille;
- int bestKFoisTaille = best.K * taille;
- int bestKPlusUnFoisTaille = bestKFoisTaille + taille;
- if (bestKPlusUnFoisTaille > nbCar)
- break;
- for (int i = taille; i <= nbCar; i++)
- {
- if (i == nbCar || chaine[i] != chaine[i-taille])
- {
- if (longueurRepetee >= bestKPlusUnFoisTaille)
- {
- best.K = longueurRepetee / taille;
- bestKFoisTaille = best.K * taille;
- bestKPlusUnFoisTaille = bestKFoisTaille + taille;
- best.i = i - (bestKFoisTaille);
- best.L = taille;
- }
- longueurRepetee = taille;
- if (best.i + bestKFoisTaille > nbCar)
- break;
- }
- else longueurRepetee++;
- }
- }
- printf("%d\n%d \n%d\n", best.K, best.L, best.i+1);
- return 0;
- }
Add Comment
Please, Sign In to add comment