LightOJ 1166 – Old Sorting

Problem:-http://www.lightoj.com/volume_showproblem.php?problem=1166


Solution :-

  1. #include <stdio.h>
  2. int main()
  3. {
  4.     int n,i,a[110],count,t,j,k,r;
  5.     scanf(“%d”,&n);
  6.     for(i=1;i<=n;i++)
  7.     {  count=0;
  8.        scanf(“%d”,&t);
  9.        for(j=1;j<=t;j++)
  10.            scanf(“%d”,&a[j]);
  11.      for(k=1;k<=t;k++)
  12.          if(a[k]!=k)
  13.      { for(j=k+1;j<=t;j++)
  14.          if(a[j]==k)
  15.      { r=a[j];
  16.       a[j]=a[k];
  17.       a[k]=r;
  18.       count++;
  19.      }
  20.      }
  21.      printf(“Case %d: %dn,i,count);
  22.     }
  23.     return 0;
  24. }

At First you can try to solve this problem if you can’t than see this code & find what’s your problem . If you copy paste this code you could not improve yourself in programming .

Posted by Shipu Ahamed

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.