title: how to find distinct value in an array
body: <p>I want to find similar values in an array. so if the value is not similar, the counter will increment by one. Code:</p>
  
  <pre><code>struct station{
      int d; //destination, one-way journey, no return
      int counter;
      int depart[10];
  };
  int main()
  {
      int n = 0; //number of stations
      int k = 0; //k is how many route one station can go
  
      scanf("%d%d",&amp;n, &amp;k);
  
      //declare array of stations based on input, n.
      struct station list[n];
  
      //Initialization
      for(int i=0; i &lt; n; i++){
          list[i].d = 0;
          list[i].counter = 0;
      }
  
      for(int i=0; i &lt; n; i++){
          int to;
          scanf("%d", &amp;to);
          list[i].d = to-1;
      }
  
     //this is where the problem is
      int ds = 0; //depart station 
      for(int ds=0; ds &lt; n; ds++){ // n is number of station
  
          list[ds].depart[list[ds].counter] = ds;
          list[ds].counter = list[ds].counter + 1;
  
          int next = list[ds].d;
          for( int j = 0; j &lt; k; j ++){ //k is how many route one station can go**
  
              list[ next ].depart[ list[ next ].counter ] = ds;
  
              if(list[ next ].depart[ list[ next ].counter ] != list[ next ].depart[ list[ next ].counter -1 ] ){
                  list[ next ].counter = list[next].counter + 1;
              }
              next = list[next].d;
          }
      }
  
      for(int i=0; i &lt; n; i++){
          printf("station [%d]: counter = %d: ", i+1 , list[i].counter);
          for(int j=0; j &lt; list[ i ].counter; j++){
                  if (list[i].depart[j] != list[i].depart[j-1] ){
                      printf("%d,", list[i].depart[j] );
              }
              }
          printf("\n");
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Input: </p>
  
  <pre><code>5 3  
  2  
  3  
  1  
  4  
  5  
  </code></pre>
  
  <p>the input is enter in a way:<br>
  (number of station) (how many route one station can go)<br>
  (station 1 goes to)<br>
  (station 2 goes to)<br>
  (station 3 goes to)<br>
  (station 4 goes to)<br>
  (station 5 goes to)  </p>
  
  <p>This is my current output:  </p>
  
  <pre><code>station [1]: counter = 3: 1,2,3  
  station [2]: counter = 2: 2,3  
  station [3]: counter = 2: 2,3  
  station [4]: counter = 2: 4,5  
  station [5]: counter = 2: 4,5  
  </code></pre>
  
  <p>note: station 2 and 3 are supposed to display 1 in the output, not only 2 and 3.</p>
  
  <p>I've tried this before:</p>
  
  <pre><code>    int ds = 0; //depart station 
      for(int ds=0; ds &lt; n; ds++){ // n is number of station
  
          list[ds].depart[list[ds].counter] = ds;
          list[ds].counter = list[ds].counter + 1;
  
          int next = list[ds].d;
          for( int j = 0; j &lt; k; j ++){ 
  
              list[ next ].depart[ list[ next ].counter ] = ds;
              list[ next ].counter = list[next].counter + 1;
  
              next = list[next].d;
          }
      }
  </code></pre>
  
  <p>The output will come out as below:</p>
  
  <pre><code>station [1]: counter = 4: 1,1,2,3  
  station [2]: counter = 4: 1,2,2,3  
  station [3]: counter = 4: 1,2,3,3  
  station [4]: counter = 4: 4,4,5,5
  station [5]: counter = 4: 4,4,5,5  
  </code></pre>