UVA 299 - Train Swapping

UVA Sep 1, 2020

Problem PDF

Solution:

#include
int main()
{
    int i,j,k,t,n,b,a[100],c;
    scanf("%d",&t);
    for(k=1;k<=t;k++)
    {
    c=0;
    scanf("%d",&n);
    for(i=0;i=i;j--)
            if(a[j-1]>a[j])
                {
                c++;
                b=a[j-1];
                a[j-1]=a[j];
                a[j]=b;
                }
    printf("Optimal train swapping takes %d swaps.\n",c);
    }
return 0;
}
https://github.com/Shipu/OnlineJudgeProblemSolutionWithCPlusPlus/tree/master/uva/299/299.cpp

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.