Re: 10327 - Flip Sort
Posted: Tue Jun 18, 2013 1:19 am
Your code never terminates.
The Online Judge board
https://uva.onlinejudge.org/board/
https://uva.onlinejudge.org/board/viewtopic.php?f=20&t=28753
According to problem description you can exchange only two adjacent terms.In this approach only one operation ( Flip ) is available and that is you can exchange two adjacent terms.
Code: Select all
#include<stdio.h>
int main()
{
int i,p[100],n,b,j,count;
while((scanf("%d",&n))==1&&n!='\0')
{
count=0;
for(i=0;i<n;i++)
{
scanf("%d",&p[i]);
}
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
if(p[j]>p[j+1])
{
b=p[j];
p[j]=p[j+1];
p[j+1]=b;
count++;
}
}
printf("Minimum exchange operations : %d\n",count);
}
return 0;
}