You are not logged in. Please login at www.codechef.com to post your questions!

×

# TSORT: Getting wa

 2 So, I used a quick sort to implement the problem in Java. It works fine for the given input set but gives wrong answer. Can someone help me please??? import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; public class Main { public static int partition(int arr[], int left, int right){ int pivot=arr[(left+right)/2]; int i=left; int j=right; int temp; while(i<=j){ while(arr[i]pivot)j--; if(i<=j){ temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; i++; j--;}} return i;} public static void QuickSort(int arr[], int left, int right){ int index=partition(arr,left,right); if(left

 4 You Picked the question in the wrong way. The question is straight forward -You just have to sort the given data-set in ascending order. But after analyzing your code ,i think you misunderstood that only one copy of the repeated members is to be printed . No ,that's not the case . And here is the proof ,For the test case 10 5 3 5 6 7 1 9 7 3 2  your code was generating the following output 1 2 3 5 6 7 9  Clearly you were avoiding the printing of repeated members. In order to fix it : Just comment the three lines in printing steps as shown :  QuickSort(turbo,0,t-1); for(int i=0;i
 3 Try the input 4 1 1 2 2  the correct answer is 1 1 2 2  you propably misunderstood non decreasing order, read more on wikipedia. Two hints to you: you don't need to implement sort in Java, there are Collections.sort() and Arrays.sort() methods quick sort in worst case has complexity O(n^2), so someone can challenge your solution in contests where it is possible to challenge (hack) solution. answered 31 May '12, 13:41 16.9k●49●115●225 accept rate: 11% @belista: Thank you for your valuable tips. As I previously stated in the comment for above post, I'm confused with the example. Any help is greatly appreciated:). (31 May '12, 19:15) avengee2★ I replied in ritesh_gupta's answer. Above or below is relative, answers are ordered by decreasing number of up votes and despite of that I answered first and ritesh_gupta copied answer 3 hours later he got more up votes... (31 May '12, 19:22) Anyways, thank you again:) (02 Jun '12, 08:11) avengee2★

# include <stdio.h>

int v[1000001]={0};

int main()

{

int n,i,a;

scanf("%d",&n);

for (i=0;i<n; i++){ scanf("%d",&a); v[a]++; }

for (n=0;n<=1000000; n++) for (i=0;i<v[n];i++) printf("%dn",n);

return 0;

}

i am getting wrong answer on this code. please someone help.

answered 10 May '13, 10:54

3626
accept rate: 0%

 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,314
×1,070
×19

question asked: 31 May '12, 12:46

question was seen: 2,100 times

last updated: 10 May '13, 10:54