আমি প্রথমে বুঝতে পারি নাই এটি কি টাইপের প্রবলেম, পরে বুঝতে পারলাম এইটা সর্টিং প্রবলেম, যাই হোক আমার পর পর ৫টি সাবমিশন Error দেখালো। আমি বুঝতে পারতেসিলাম না আমার সমস্যা কোথায়। একটা সময় পর আমি বুঝতে পারলাম আমার সর্টিং অ্যালগরিদমটাই ঠিক নাই। তার মানে আমি আগে যে বাবল সর্টিং অ্যালগরিদম শিখছিলাম সেটা ভুল ছিল :D ।
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*------------------------------------------------*/ | |
//Uva Problem No: 299 | |
//Problem Name : Train Swapping | |
//Author : Shohanur Rahaman | |
//University : City University | |
//E-mail : shohan4556@gmail.com | |
//Problem Type: Sorting | |
/*-----------------------------------------------*/ | |
#include<stdio.h> | |
int main() | |
{ | |
int i,j,k,t_case,n,t,train[51],count; | |
while(scanf("%d",&t_case)==1){ | |
for(k=0;k<t_case;k++){ | |
count=0; | |
scanf("%d",&n); | |
for(i=0;i<n;i++) | |
scanf("%d",&train[i]); | |
for(i=0;i<n-1;i++) | |
for(j=0;j<n-i-1;j++) | |
if(train[j]>train[j+1]){ | |
count++; | |
t=train[j]; | |
train[j]=train[j+1]; | |
train[j+1]=t; | |
} | |
printf("Optimal train swapping takes %d swaps.\n",count); | |
} | |
} | |
return 0; | |
} |