you are not supposed to post code. Just post pseudo code to explain logic.
On Fri, Aug 17, 2012 at 12:05 PM, Sairam Ravu <[email protected]> wrote:
> #include <iostream>
> #include <map>
> #include <stdlib.h>
>
> using namespace std;
>
> int main()
> {
> int testcases;
> cin >> testcases;
>
> int Inputsize[200000];
> int *Output[testcases];
>
> int i;
>
> for(i=0;i<testcases;i++)
> {
> int inputsize=0;
> int *Order;
> cin >> inputsize;
>
>
>
> Order = (int *)malloc(sizeof(int)*(inputsize+1));
>
> int j;
> int value;
> for(j=0;j<inputsize;j++)
> {
> cin >> value;
> Inputsize[j] = value;
> Order[j] = j+1;
> }
> Order[j] = '\0';
>
> int temp;
> int tempOrder;
> int tempIndex;
>
>
> for(j=0;j<inputsize;j++)
> {
>
> temp = Inputsize[j];
> tempIndex = j;
>
> while(temp)
> {
>
> tempOrder = Order[tempIndex-1];
> Order[tempIndex-1] = Order[tempIndex];
> Order[tempIndex] = tempOrder;
> tempIndex--;
> temp--;
>
> }
>
> }
>
> //Now have a map between the Order and the index of it
>
> map<int,int> MapOrder;
> map<int,int>::iterator iter;
>
> for(j=0;j<inputsize;j++)
> {
> MapOrder[Order[j]] = j+1;
> }
>
>
> for(j=0,iter=MapOrder.begin();iter!=MapOrder.end();iter++,j++)
> Order[j] = iter->second;
>
> Output[i] = Order;
>
> }
>
> //Now print the output
>
> int j;
> for(i=0;i<testcases;i++)
> {
> for(j=0;Output[i][j]!='\0';j++)
> cout<<Output[i][j]<<" ";
> cout<<endl;
> }
>
> }
>
>
> Code is giving correct results- but it is running out of time. Can you
> suggest some way to get out of it?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.