10327 - Flip Sort
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10327 - Flip Sort
Your code never terminates.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 1
- Joined: Sat Dec 07, 2013 7:47 pm
10327 - Flip Sort
I think the problem has some difficulties. Why i can,t change the values between each other. why i can't swap. with out swapping i can't sort my values... Admin please clear me...
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10327 - Flip Sort
Check input and AC output for thousands of problems on uDebug!
Re: 10327 - Flip Sort
DELETED
Last edited by xrenon on Sun Oct 12, 2014 2:55 pm, edited 1 time in total.
Re: 10327 - Flip Sort
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.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Re: 10327 - Flip Sort
I would like to argue that the problem is ill-posed. At least, there's a conflict between the text (a number N followed by several lines) while the sample input showed two data sets with two "different" N as one can see in the sample output.
The reference program at udebug seemed to agreed with the problem text, but seems to ignore the number N and process each line individually. For example
3
1 2 3
3 2 1
4
1 2 3 4
4 2 3 1
would give 5 lines and treats the last 3 lines as permutation on 4 letters, not 3.
The reference program at udebug seemed to agreed with the problem text, but seems to ignore the number N and process each line individually. For example
3
1 2 3
3 2 1
4
1 2 3 4
4 2 3 1
would give 5 lines and treats the last 3 lines as permutation on 4 letters, not 3.
Re: 10327 - Flip Sort
why my code is getting is runtime error...plz help..
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;
}