dimanche 4 octobre 2020

how to find number of pages and number of lines on the current page respect to speed after a specified interval of time?

A student has created a software which will read from one book and write into another book . Both books may have different dimensions. Software first reads from the book fully then process the format to write into another book. Yours task is to identify after a specified interval of time , if software is reading or writing. for each of these activities how much read and write activity has happened needs to be captured in terms of page and number of lines on the current page.

Input

ln1 -> number of lines per page in first book
pn2 -> number of pages in second book
ln2 -> number of lines per pages in second book
rs -> reading speed in lines/seconds
ws -> writing speed in lines/seconds
t -> time in seconds at which the result is to be processed

Output

print current activity (READ or WRITE),page number and line number

Example

Input
100
10
500
6
8
4
145

Output
WRITE 13 2

Code :

import java.util.*;

public class MyClass {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int pn1 = sc.nextInt();
        int ln1 = sc.nextInt();
        int pn2 = sc.nextInt();
        int ln2 = sc.nextInt();
        int rs = sc.nextInt();
        int ws = sc.nextInt();
        int t = sc.nextInt();
        int i,j,s1,s2,s3=0;
        s1 = pn1 * ln1;
        s2 = s1/rs;
        if(s2<t)
        {
            System.out.print("WRITE ");
            for(i=1;i<=pn2;i++)
            {
                for(j=1;j<=ln2;j=j+ws)
                {
                    if(s2==t)
                    {
                        break;
                    }
                    s2++;
                }
                if(j<=ln2)
                {
                    System.out.print(i+ " " +j);
                    break;
                }
            }
        }
        else
        {
            System.out.print("READ ");
            for(i=1;i<=pn1;i++)
            {
                for(j=1;j<=ln1;j=j+rs)
                {
                    if(s3==t)
                    {
                        break;
                    }
                    s3++;
                }
                if(j<=ln1)
                {
                    System.out.print(i+ " " +j);
                    break;
                }
            }
        }
    }
}

My output : WRITE 11 1

Can anyone please help where I m going wrong , Because in my if else statement j value is not incrementing it will always print 1 as it will be initialized as 1 in for loop . Thank you in advanced .

Aucun commentaire:

Enregistrer un commentaire