Submit solution
Points:
1.00 (partial)
Time limit:
1.0s
Memory limit:
256M
Input:
stdin
Output:
stdout
Author:
Problem source:
Problem type
Allowed languages
C, C#, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
28Tech cho bạn 1 mảng toàn số 0 và 1, bạn hãy in ra độ dài của các dãy con toàn số 0 liên tiếp và toàn số 1 liên tiếp.
Ví dụ : mảng A[] = {1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0} thì có 3 dãy con số 1 liên tiếp có độ dài là 3, 1, 2 và 3 dãy con số 0 liên tiếp có độ dài là 2 1 2
Đầu vào
Dòng 1 là N : số phần tử trong mảng
Dòng 2 là N số trong mảng viết cách nhau 1 dấu cách
Giới hạn
1<=N<=10000
0<=A[i]<=1
Đầu ra
Dòng 1 in ra độ dài của các dãy con số 1 liên tiếp
Dòng 2 in ra độ dài của các dãy con số 0 liên tiếp
Ví dụ :
Input 01
10
1 0 0 0 0 0 1 1 0 1
Output 01
1 2 1
5 1
Comments
FULL AC
include <bits/stdc++.h>
using namespace std; typedef long long ll;
define fastio iosbase::syncwith_stdio(false); cin.tie(NULL);
int main() { fastio int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; a[n] = 0; int cnt = 0; for (int i = 0; i <= n; i++) { if (a[i] == 1) { cnt++; } else { if (cnt>0) cout << cnt << ' '; cnt = 0; } } cout << '\n'; a[n] = 1; for (int i = 0; i <= n; i++) { if (a[i] == 0) { cnt++; } else { if (cnt>0) cout << cnt << ' '; cnt = 0; } } return 0; }
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.