fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <climits>
  5. #include <algorithm>
  6. #include <numeric>
  7.  
  8. using namespace std;
  9.  
  10. const int MOD = (int)(1e9 + 7);
  11.  
  12.  
  13. int main() {
  14. ios_base::sync_with_stdio(false);
  15. cin.tie(NULL);
  16.  
  17. int n;cin >> n;
  18. int a[n];
  19. for (int i = 0;i < n;i++) {
  20. cin >> a[i];
  21. }
  22.  
  23. int current_one = 0;
  24. for (int i = 0;i < n;i++) {
  25. if (a[i] == 1) {
  26. current_one++;
  27. }
  28. else {
  29. if (current_one != 0) {
  30. cout << current_one << " ";
  31. current_one = 0;
  32. }
  33. }
  34. }
  35. if (current_one != 0) {
  36. cout << current_one << " ";
  37. current_one = 0;
  38. }
  39.  
  40. int current_zero = 0;
  41. for (int i = 0;i < n;i++) {
  42. if (a[i] == 0) {
  43. current_zero++;
  44. }
  45. else {
  46. if (current_zero != 0) {
  47. cout << current_zero << " ";
  48. current_zero = 0;
  49. }
  50. }
  51. }
  52. if (current_zero != 0) {
  53. cout << current_zero << " ";
  54. current_zero = 0;
  55. }
  56. return 0;
  57. }
  58.  
  59.  
  60.  
Success #stdin #stdout 0s 5348KB
stdin
Standard input is empty
stdout
1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4174 1 1 1 1 2 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 2 1 1 1 4 2 1 1 2 1 1 2 1 1 1 1 3 1 1 1 1 1 3 1 7 2 3 2 4 1 4 1 1 2 1 1 2 6 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 2 1 1 1 3 1 2 1 3 1 2 1 2 2 2 1 1 4 3 1 2 1 4 1 1 1 2 5 1 2 2 17 60 83 1 1 2 1 1 2 2 4 2 2 2