Coding Discussions
Would you like to react to this message? Create an account in a few clicks or log in to continue.

in ipl question.the test case 2nd is wrong.my solution is correct.

2 posters

Go down

in ipl question.the test case 2nd is wrong.my solution is correct. Empty in ipl question.the test case 2nd is wrong.my solution is correct.

Post by akarshsomani Fri Apr 14, 2017 12:09 pm

in second test case,
one of the input is
126
16 1 9 13 10 5 7
according to this input the output should be 6.2,but in expected output it is given 6.3.

another input is
154
16 9 16 3 12 12 1
according to this input the output should be 8.3,but in expected output it is given 8.4.


My program
import java.util.Scanner;

class p1 {
public static void  main(String args[])
{
Scanner sc=new Scanner(System.in);

int t=sc.nextInt();
while(t-->0)
{

int tottal=sc.nextInt();
int a[]=new int[7];
int b[]=new int[6];
for(int i=0;i<7;i++)
{
a[i]=sc.nextInt();
}

int balls=0;
b[5]=6;b[4]=4;b[3]=3;b[2]=2;b[1]=1;b[0]=0;
if(tottal<=a[6])
tottal=0;
if(tottal>0)
{
for(int i=5;i>2;i--)
{
for(int j=0;j<a[i];j++)
{
if(tottal<=a[6])
tottal=0;
if(tottal>=b[i])
{
tottal-=b[i];
balls++;
}
else
break;
}

}
tottal-=a[6];

while(a[2]>0&&a[0]>0)
{

if(tottal>=2)
{
tottal-=2;
balls+=2;
a[2]--;a[0]--;
}
else
break;
}
while(a[1]>0)
{

if(tottal>=1)
{
tottal-=1;
balls++;
a[1]--;
}
else
break;
}
}
int rem=balls%6,div=balls/6;

System.out.println(div+"."+rem);

}
}
}

akarshsomani

Posts : 21
Join date : 2017-04-04

Back to top Go down

in ipl question.the test case 2nd is wrong.my solution is correct. Empty Re: in ipl question.the test case 2nd is wrong.my solution is correct.

Post by Compact_Coder Fri Apr 14, 2017 1:05 pm

3rd test case of my code is also not running,although I have a very clearer code.
Code:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int min_balls(){
    int target,m,balls=0;
    scanf("%d",&target);
    int runs[7];
    for(int i=0;i<7;i++)
        scanf("%d",&runs[i]);
    target-=runs[6];
    while(target>0 && runs[5]-->0){
        target-=6;
        balls++;
    }
    while(target>0 && runs[4]-->0){
        target-=4;
        balls++;
    }
    while(target>0 && runs[3]-->0){
        target-=3;
        balls++;
    }
    runs[1]+=2*runs[2];
    while(target>0 && runs[1]-->0){
        target-=1;
        balls++;
    }
    return balls;
}

int main() {
    int t;
    scanf("%d",&t);
    while(t--){
        int balls=min_balls();
        float overs=(balls/6) + (float)(balls%6)/10.0;
        printf("%.1f\n",overs);
    }

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    
    return 0;
}

Compact_Coder

Posts : 1
Join date : 2017-04-14

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum