Coding Quiz - Tom & Jerry Construction problem [closed]

Tom has taken a contract for construction to achieve a (N) number of work for (T) amount of test cases.

Tom can construct (C) number of work in the morning, Jerry destroys (D) number of work in the evening. 

For each of (T) test cases, calculate the days of work Tom can utilize to complete the work to achieve (N) works.

Constraints:

1 <= T <= 100000
1 < D < C < N < 100000

Input format:

T -> Test case
C D N

Input should accept T test case followed by the C, D and N with one whitespace (" ").

Input:

2
6  2  10
4  3  10

Output:

2
7

I would appreciate a solution in any programming language.

My Trial Attempt

The issue with the code is it is not returning the expected output.

Output of the below code:

2
9

This is the logic as per my assumption. Debugging details are included on top of the code (logic assumption for the problem)

// Execution Logic for Test case 2 -
// D - Days, T - TomUnits, J - JerryUnits, Pr - TomProgress
// D-1 : T - 4, J - 3, Pr = 1, Nr - 10-1 = 9
// D-2 : T - 4+1, J - 3, Pr = 2, Nr - 9-2 = 7
// D-3 : T - 4+2, J - 3, Pr = 3, Nr - 7-3 = 4
// D-4 : T - 4+3, J - 3, Pr = 4, N4 - 4-4 = 0
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class Code {
    static void Main(String[] args) {
        int n = Convert.ToInt32(Console.ReadLine());
        List<List<int>> works = new List<List<int>>();
        // Reads for n inputs spaced by one empty character
        for (int i = 0; i < n; i++) {
            works.Add(Console.ReadLine().TrimEnd().Split(' ').ToList()
            .Select(c => Convert.ToInt32(c)).ToList());
        } 

        int[] days = new int[n];

        for(int i = 0; i < n; i++) {
            int daysPerCase = 0;
            int unitsPerCase = works[i][2];
            int tomUnits = works[i][0];
            int jerryUnits = works[i][1];
            int tomProgress = 0;
            int tomRemainingUnits = 0;
    
            // Return 1 day if no total case or jerry case
            if(unitsPerCase == 0)
                daysPerCase = 2;
    
            while(tomRemainingUnits < unitsPerCase) {           
                tomRemainingUnits += tomUnits - jerryUnits;
                tomProgress += tomRemainingUnits - jerryUnits;   
                daysPerCase++;
            }
            days[i] = daysPerCase - 1;
        }
        
        for(int i = 0; i < days.Length; i++) {
            Console.WriteLine("{0}", days[i]);
        }
        
    }
}


from Recent Questions - Stack Overflow https://ift.tt/3iEUXU4
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)