Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int n, j, count, fita[10100], fitaV[10100];
- cin>>n;
- for(int i = 0; i < n; i++) {
- cin>>fita[i];
- fitaV[i] = fita[i];
- }
- for(int i = 0; i < n; i++) {
- if(fita[i] == 0) {
- // Ida
- j = i + 1;
- count = 1;
- while(fita[j] != 0 && j < n) {
- if(fita[j] == -1)
- fita[j] = count;
- j++;
- count++;
- }
- // Volta
- j = i - 1;
- count = 1;
- while(fitaV[j] != 0 && j >= 0) {
- if(fitaV[j] == -1)
- fitaV[j] = count;
- j--;
- count++;
- }
- }
- }
- for(int i = 0; i < n; i++) {
- if(fita[i] == -1) cout<<fitaV[i]<<" ";
- else if(fitaV[i] == -1) cout<<fita[i]<<" ";
- else if(fitaV[i] == 0 && fita[i] == 0) cout<<"0 ";
- else if(fita[i] < fitaV[i]) cout<<fita[i]<<" ";
- else if(fitaV[i] < fita[i]) cout<<fitaV[i]<<" ";
- else if(fitaV[i] == fita[i]) cout<<fita[i]<<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement