Enjoy Number Technique with Tom and Jerry Fight Game

Query: Let's play a game with numbers connecting it with our childhood memories, As we have seen Tom & Jerry fight in cartoons now let's have number game based on Tom and Jerry fight. Tom is working as top architect of the company and he has given work on NumberofTask no. sites, seeing the progress of Tom, Jerry become jealous from Tom and he decided to disrupt the image of Tom. So he started to destroy the C no. buildings in nights that D no. of buildings Tom created in a day. In the end Tom gets successful in completing the project on all sites by constructing N no. of buildings per (N) sites. Now you have to calculate the minimum time that has been taken by Tom to complete the project?

Constraints:

1<= NumberofTask  <= 100

1<= N <= 10^5

1<= C <= D

1<=D <= N

                                                        Test Cases Example

Input will be given in below format:

First Line: Number of Tasks assign to Tom
Second Line: D(Tom Constructed) C(Jerry Destroyed) N(Total building for this site)  This input will be for each task assign to Tom

First try it yourself than if you find any challenge take the help from solution

I have try to write a code that can help user to understand the best possible use of List. There could be many technique to write the code for this problem, I have tried my technique you can try yours but keep in mind the complexity should be always the key before writing the solution.

Solution Using C#:


    using System;
    using System.Collections.Generic;
    using System.Linq;

    namespace NewYearGame
    {
        class Program
        {
            static void Main(String[] args)
            {
                int NumberofTask = Convert.ToInt32(Console.ReadLine());

                if(NumberofTask>=1 && NumberofTask <= 100)
                {
                    List taskList = new List();
                    for(int i = 0; i < NumberofTask; i++)
                    {
                        taskList.Add(Console.ReadLine());
                    }

                    foreach(string s in taskList)
                    {
                        string[] task = s.Split(" ");
                        int days = 0;
                        if (task.Length == 3)
                        {
                            int C = Convert.ToInt32(task[0]);
                            int D = Convert.ToInt32(task[1]);
                            int N = Convert.ToInt32(task[2]);

                            if(N>=1 && N<= Math.Pow(10,5) && D>=1 && C <= N)
                            {
                                int temp = 0;
                                while (temp <= N)
                                {
                                    temp += C;
                                    if (temp >= N)
                                    {
                                        break;
                                    }
                                    temp = temp - D;
                                    days++;
                                }
                            }
                        }
                        Console.WriteLine(days + 1);
                    }
                }
                Console.Read();
            }
        }
    }
  

Comments