Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Implementare Dan Pracsiu - 100p
- */
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream fin("vecine.in");
- ofstream fout("vecine.out");
- int n, a[100003];
- void F1()
- {
- int i, cnt = 0;
- for (i = 1; i < n; i++)
- if (a[i] + 1 == a[i + 1]) cnt++;
- fout << cnt << "\n";
- }
- void F2()
- {
- int i, j, L, k;
- long long x, y, ans = -1;
- L = min(10, n / 2);
- for (k = L; k >= 1; k--)
- {
- /// cautam daca exista doua numere alaturate consecutive de k cifre
- for (i = 1; i <= n - 2 * k + 1; i++)
- if (a[i] != 0)
- {
- x = y = 0;
- for (j = 0; j < k; j++)
- x = x * 10 + a[i + j];
- for (j = 0; j < k; j++)
- y = y * 10 + a[i + k + j];
- if (x + 1 == y)
- ans = max(ans, x);
- /// verific daca x si y nu sunt de forma x=999, y=1000
- if (i + 2 * k <= n)
- {
- y = y * 10 + a[i + 2 * k];
- if (x + 1 == y) ans = max(ans, x);
- }
- }
- else if (k == 1 && a[i + 1] == 1)
- ans = max(ans, 0LL);
- }
- fout << ans << "\n";
- }
- int main()
- {
- int task;
- fin >> task >> n;
- for (int i = 1; i <= n; i++)
- fin >> a[i];
- if (task == 1) F1();
- else F2();
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement