Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main(){
- int t[] = { 1, 0, 12, 0, 4, 0, 0, 8 };
- int n = 8, i=0;
- while (i<n){
- if (t[i] == 0){
- int k = i + 1;
- while (k < n && t[k] == 0)k++;
- if (k == n) break;
- for (int j = i; j < n - 1; j++)
- t[j] = t[j + k - i];
- for (int j = 0; j < k - i; j++)
- t[n - 1 - j] = 0;
- }
- i++;
- }
- for (int j = 0; j < n; j++)
- cout << t[j] << ", ";
- cout << "\n";
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment