Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n, j, count, fita[10100], fitaV[10100];
  7.     cin>>n;
  8.     for(int i = 0; i < n; i++) {
  9.         cin>>fita[i];
  10.         fitaV[i] = fita[i];
  11.     }
  12.  
  13.     for(int i = 0; i < n; i++) {
  14.         if(fita[i] == 0) {
  15.             // Ida
  16.             j = i + 1;
  17.             count = 1;
  18.             while(fita[j] != 0 && j < n) {
  19.                 if(fita[j] == -1)
  20.                     fita[j] = count;
  21.                 j++;
  22.                 count++;
  23.             }
  24.  
  25.             // Volta
  26.             j = i - 1;
  27.             count = 1;
  28.             while(fitaV[j] != 0 && j >= 0) {
  29.                 if(fitaV[j] == -1)
  30.                     fitaV[j] = count;
  31.                 j--;
  32.                 count++;    
  33.             }
  34.         }
  35.     }
  36.  
  37.     for(int i = 0; i < n; i++) {
  38.         if(fita[i] == -1) cout<<fitaV[i]<<" ";
  39.         else if(fitaV[i] == -1) cout<<fita[i]<<" ";
  40.         else if(fitaV[i] == 0 && fita[i] == 0) cout<<"0 ";
  41.         else if(fita[i] < fitaV[i]) cout<<fita[i]<<" ";
  42.         else if(fitaV[i] < fita[i]) cout<<fitaV[i]<<" ";
  43.         else if(fitaV[i] == fita[i]) cout<<fita[i]<<" ";
  44.     }
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement