Number sort. getting wrong answer. what's wrong?

Dev Skill archived problems can be discussed here.

Number sort. getting wrong answer. what's wrong?

by Dinar » Mon Sep 26, 2016 7:37 pm

Code: Select all
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

class Solution {

    public static void main(String[] args) {
        int t,n;
        Scanner input=new Scanner(System.in);
        t=input.nextInt();
        String[] str=new String[1001];
        for(int i=0;i<t;i++){
            n=input.nextInt();
            for(int j=0;j<n;j++){
                str[j]=input.next();
            }
            String smallest;
            int index;
            for(int j=0;j<n-1;j++){
                smallest=str[j];index=0;
                for(int x=j+1;x<n;x++){
                    if(Float.valueOf(smallest)>Float.valueOf(str[x])){
                        smallest=str[x];
                        index=x;
                    }
                }
                if(index>0){
                    str[index]=str[j];
                    str[j]=smallest;
                }
            }
            for(int j=0;j<n;j++)
                if(j==n-1)
                System.out.print(str[j]);
                else System.out.print(str[j]+",");
            System.out.println();
        }
    }
}
 
Posts: 8
Joined: Thu Sep 22, 2016 9:14 pm

Re: Number sort. getting wrong answer. what's wrong?

by devskill » Tue Sep 27, 2016 10:45 pm

Input:
Code: Select all
1
4
999.00 999 222 222.00


Output:
Code: Select all
222,222.00,999.00,999


Edit: Yes, it should have comma, edited it
User avatar
Site Admin
 
Posts: 118
Joined: Tue Feb 02, 2016 10:24 pm

Re: Number sort. getting wrong answer. what's wrong?

by Dinar » Wed Sep 28, 2016 7:47 pm

I got the same answer except the comma. shoudn't I use the comma between numbers? My answer is
Code: Select all
222,222.00,999.00,999
 
Posts: 8
Joined: Thu Sep 22, 2016 9:14 pm

Re: Number sort. getting wrong answer. what's wrong?

by devskill » Wed Sep 28, 2016 10:01 pm

Hi, your previous solution was correct. We found a small mistake in judge data. We have corrected and rejudged your solution and it got Accepted. We will rejudge all solution for this problem tonight.

For helping us in finding this problem, we will give you 50 DP.
User avatar
Site Admin
 
Posts: 118
Joined: Tue Feb 02, 2016 10:24 pm

Re: Number sort. getting wrong answer. what's wrong?

by Dinar » Wed Sep 28, 2016 10:45 pm

Thanks
 
Posts: 8
Joined: Thu Sep 22, 2016 9:14 pm

Number Formatting

by MarufAhmed » Mon Dec 19, 2016 12:25 pm

prb link : http://www.devskill.com/CodingProblems/ViewProblem/194

Why WA?

my code:

#include<stdio.h>
#include<string.h>
main()
{
int t,i,j,k;
scanf("%d",&t);
char ch[] = "abcd";
char p[10][5]={"011","015","016","017","018","019"};
char p1[10][17]={"Citycell","Teletalk","Airtel","Grameenphone","Robi","Banglalink"};
for(i=0;i<t;i++)
{
char s[15],c[15];
scanf("%s",s);

if(strlen(s)!=11)
{
for(j=2;j<13;j++)
{
c[j-2]=s[j];
}
}
else
{
for(j=0;j<11;j++)
{
c[j]=s[j];
}
}
for(j=0;j<6;j++)
{
if(strcmp(p[j],c)==1)
{
printf("88");
for(k=0;k<11;k++)
printf("%c",c[k]);
printf(" %s\n",p1[j-1]);
break;
}
}



}
}
 
Posts: 3
Joined: Sun Dec 18, 2016 11:21 pm


Who is online
Users browsing this forum: No registered users and 1 guest
cron