本站遷移

因為我最近租用了網路空間以及網域,
故本站已遷移至新網站~
這邊的資訊已經正在進行搬移的工作~
希望各位可以到新網站去逛XD

New Website:
http://knightzone.org/

搜尋此網誌

2011年3月4日 星期五

[UVa]10327:Flip Sort

即是計算Bubble Sort的交換次數。

[C](0.088)
#include<stdio.h>
int main()
{
int N;
while( scanf( "%d", &N ) != EOF )
{
int array[1005] = {0};
int i, j;
for( i = 0 ; i < N ; i++ )
scanf( "%d", &array[i] );
int swap = 0;
for( i = 0 ; i < N ; i++ )
for( j = N-1 ; j > i ; j-- )
if( array[j] < array[j-1] )
{
array[j] ^= array[j-1] ^= array[j] ^= array[j-1];
swap++;
}
printf( "Minimum exchange operations : %d\n", swap );
}
return 0;
}
view raw UVa10327.c hosted with ❤ by GitHub

0 意見:

張貼留言