Thursday, September 13, 2018

THROW THIS DUPES!!!


  • Problem Description

    Sudhans teacher give a task to him. She gave a set of numbers that consists of several replications. She ask sudhan to remove the duplicate numbers from the set. Your task is to help sudhan to do this work.
  • CODING ARENA
  • #include <stdio.h>
    int main()
    {
      int a[20],i,j,k,n;
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
        scanf("%d",&a[i]);
      }
      for(i=0;i<n;i++)
      {
        for(j=i+1;j<n;)
        {
          if(a[j]==a[i])
          {
            for(k=j;k<n;k++)
            {
              a[k]=a[k+1];
            }
            n--;
          }
          else
          {
            j++;
          }
        }
      }
      for(i=0;i<n;i++)
      {
        printf("%d ",a[i]);
      }
    return 0;
    }
  • Test Case 1

    Input (stdin)
    5 
    
    1 3 3 1 1
    
    
    Expected Output
    1 3
  • Test Case 2

    Input (stdin)
    9
    
    45 78 12 10 12 45 78 12 45
    
    
    Expected Output
    45 78 12 10

1 comment:

  1. How to get a space between the output . Because I am getting 13 and 45781210

    ReplyDelete