Turbo Sort

March 12, 2009 at 10:30 am 2 comments

http://www.codechef.com/problems/TSORT/

A good small program (in C or C++ preferably) should solve this.

About these ads

Entry filed under: Puzzles. Tags: .

Compute path distance Sums in a triangle

2 Comments Add your own

  • 1. narinderberi  |  March 12, 2009 at 10:32 am

    I simply chose to solve this one via Count Sort. Allocate an array of size 1000001 (note that the range of numbers is 0 to 1000000 both inclusive).

    Here is the code:
    #include
    #include

    void turbosort()
    {
    int count;

    scanf(“%d”, &count);

    int *arr = new int[1000001];
    memset(arr, 0, 1000001 * sizeof(int));

    int num;
    for(register int i = 1; i <= count; ++i)
    {
    scanf(“%d”, &num);
    ++arr[num];
    }

    for(register int i = 0; i <= 1000000; ++i)
    {
    for(register int j = 1; j <= arr[i]; ++j)
    printf(“%d\n”, i);
    }

    delete []arr; arr = NULL;
    }

    int main()
    {
    turbosort();
    return 0;
    }

  • 2. Van  |  October 20, 2011 at 3:05 am

    #include
    int main()
    {
    int t,n[100001],i,j,k,temp;
    scanf(“%d”,&t);
    if(t<=1000000)
    {
    for(i=0;i<t;i++)
    scanf("%d",&n[i]);
    }
    else
    {
    return 0;
    }
    for (i=0;i<t;i++)
    {
    for(j=i+1;jn[j])
    {
    temp=n[i];
    n[i]=n[j];
    n[j]=temp;
    }
    }
    }
    for(i=0;i<t;i++)
    {
    printf("%d\n",n[i]);
    }
    return 0;
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Blog Stats

  • 3,422 hits

Recent Comments


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: