Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <algorithm>
- #include <string>
- #include <map>
- #include <cmath>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- int t;
- cin >> t;
- while (t--) {
- int n;
- cin >> n;
- int arr[n];
- bool f=0,g=1;
- bool h=0;
- for (int i=0; i<n; i++) {
- cin >> arr[i];
- if (arr[i]==0) f=1;
- if (arr[i]!=0) g=0;
- }
- for (int i=1; i<n-1; i++) {
- if (arr[i]==0 && arr[i-1]!=0 && arr[i+1]!=0) {
- h=1; break;
- }
- }
- if (g) {
- cout << 0 << endl;
- }
- else if (!f) cout << 1 << endl;
- else if (arr[0]==0 && arr[n-1]==0 && h) cout << 2 << endl;
- else if (arr[0]==0 || arr[n-1]==0) cout << 1 << endl;
- // if (f) cout << 2 << endl;
- else cout << 2 << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment