The Programming Project: ISC
Showing posts with label ISC. Show all posts
Showing posts with label ISC. Show all posts

Monday, December 15, 2025

ISC Computer Science Theory Paper 2023 Program Transpose of a Matrix

 





import java.util.*;

public class Matrix {

    public static void main(String[] args) {

        // Create a single Scanner object for System.in
        Scanner scanner = new Scanner(System.in);

        // Pass the single Scanner object to the Trans constructor
        Trans obj = new Trans(scanner);

        obj.fillarray();
        obj.display();

        // Close the Scanner
        scanner.close();
    }
}

class Trans {

    private int m;
    private int[][] arr;
    private int[][] arrT;
    private Scanner in;

    Trans(Scanner scanner) {
        this.in = scanner;
        System.out.println("Enter the order (size) of the square matrix:");
        this.m = in.nextInt();
        this.arr = new int[m][m];
        this.arrT = new int[m][m];
    }

    public void fillarray() {
        System.out.println("\n--- Entering elements for the " + m + "x" + m + " matrix ---");
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < m; j++) {
               
                System.out.println("Input element at [" + i + "][" + j + "]:");
                arr[i][j] = in.nextInt();
            }
        }
    }

    public void display() {
        System.out.println("\nORIGINAL MATRIX:");
        printMatrix(arr);

        transpose();
    }

    private void transpose() {
        System.out.println("\nTRANSPOSE OF THE MATRIX:");
        // The core logic for transpose: ArrT[i][j] = Arr[j][i]
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < m; j++) {
                arrT[i][j] = arr[j][i];
            }
        }
        printMatrix(arrT);
    }

    // Helper method for cleaner printing and better formatting
    private void printMatrix(int[][] matrix) {
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < m; j++) {
                // Use format for aligned columns, which improves readability
                System.out.format("%5d", matrix[i][j]);
            }
            System.out.println();
        }
    }
}

Sunday, December 14, 2025

ISC Computer Science Theory Paper 2023 Program Dudeney Number

 




import java.util.Scanner;

public class Dudeney {

    public static void main(String[] args) {

        NumDude obj = new NumDude();
        obj.input();
        obj.isDude();

    }

}

class NumDude {

    public void isDude() {
        if (numb == (int) Math.pow(sumDigits(numb), 3)) {
            System.out.println(numb + " is a Dudeney Number");
        }else {
            System.out.println(numb + " is not a Dudeney Number");
        }
    }

    private int sumDigits(int x) {
        if (x > 10) {
            return ((x % 10) + sumDigits(x / 10));
        } else {
            return x;
        }

    }

    public void input() {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a positive integer: ");
        numb = scanner.nextInt();
        scanner.close();
    }

    public NumDude() {
        this.numb = 0;
    }
    private int numb;

}

🔢 Dudeney Number Checker

A Dudeney number is a positive integer that is a perfect cube such that the sum of its decimal digits equals the cube root of the number.

🎯 Examples:

  • 1 = 1³ and 1 = 1
  • 512 = 8³ and 5+1+2 = 8
  • 4913 = 17³ and 4+9+1+3 = 17
  • 5832 = 18³ and 5+8+3+2 = 18

Try numbers like: 1, 512, 4913, 5832, 17576, 19683

Sunday, January 8, 2023

Leet Code Roman to Integer

Roman numerals are represented by seven different symbols: IVXLCD and M.

Symbol       Value
I                   1
V                  5
X                 10
L                  50
C                 100
D                 500
M               1000

  For example, 2 is written as II in Roman numeral, just two ones added together. 12 is written as XII,       which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.

 Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is   not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making   four. The same principle applies to the number nine, which is written as IX. There are six instances where   subtraction is used:

  • I can be placed before V (5) and X (10) to make 4 and 9. 
  • X can be placed before L (50) and C (100) to make 40 and 90. 
  • C can be placed before D (500) and M (1000) to make 400 and 900.

 Given a roman numeral, convert it to an integer.

 

 Example 1:

Input: s = "III"
Output: 3
Explanation: III = 3.

 Example 2:

Input: s = "LVIII"
Output: 58
Explanation: L = 50, V= 5, III = 3.

 Example 3:

Input: s = "MCMXCIV"
Output: 1994
Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.

 

 Constraints:

  • 1 <= s.length <= 15
  • s contains only the characters ('I', 'V', 'X', 'L', 'C', 'D', 'M').
  • It is guaranteed that s is a valid roman numeral in the range [1, 3999].
 Explanation:
The logic of the program is explained below with the example of MCMXCIV.
Take the value of each of the letters in the sequence:
1000 = M, 100 = C, 1000 = M, 10 = X, 100 = C, 1 = I, 5 = V
Keed adding the values in a variable. But for the second position onwards we
have check the difference of the value of the current position and the previous
position. If the difference is 4 or 9 or 40 or 90 or 400 or 900 then by the exception
rule we have to adjust the value.
For the example above, as 100-1000 = -900 ( i = 1 and i = 0) which is not under
exception rule we add 1000+100 = 1100
But for the next letter ('M') the value is 1000 ( i = 2 ) and 1000 - 100 = 900
( under exception rule), so instead of adding 1000 to 1100 we have to have add 900
to the value of the first letter ( since CM is forming a single value). For this
we need to subtract the value of the current letter (M = 1000) and the previous
letter ( C = 100 ) from the sum of 1000+100+1000 = 2100 and add 900.
Which gives 2100-1000 - 100 + 900 = 1900.


PYTHON CODE

class Solution(object):

    def romanToInt(self, s):
        temp = 0
        for i in range(len(s)):
            self.output += self.value[self.position(s[i])]
            #print ("BEFORE ADJUSTMENT",self.output)
            if i > 0:
                temp = (self.value[self.position(s[i])] -
                        self.value[self.position(s[i - 1])])
            if temp == 4 or temp == 9 or temp == 40 or temp == 90 or temp == 400 or temp == 900:
                self.output = self.output - self.value[self.position(
                    s[i - 1])] - self.value[self.position(s[i])] + temp
            #print ("AFTER ADJUSTMENT",self.output)
        return self.output

    def position(self, symb):
        counter = 0
        while symb != self.symbol[counter]:
            counter += 1
        return (counter)

    symbol = ['I', 'V', 'X', 'L', 'C', 'D', 'M']
    value = [1, 5, 10, 50, 100, 500, 1000]
    output = 0


obj = Solution()
s = str(input("Enter a valid roman numeral in range(1,3999):"))
print(obj.romanToInt(s))

Wednesday, September 29, 2021

ISC COMPUTER SCIENCE PRACTICAL SPECIMEN PAPER 2021 : QUESTION 2 STRING

ISC COMPUTER SCIENCE PRACTICAL SPECIMEN PAPER 2021

Try out with different inputs

ENTER THE SENTENCE:


In most of the problems based on Strings in ISC Computer Science Practical it is common to test the validity of the sentence. In most of the cases the statement is terminated by either '.', '?' or '!' and are separated by a single blank and have only upper case characters or only lower case characters.
                            In most of my programs I have checked only for the terminating characters and the case for the characters. But in this program I have tested that the word must be separated by only one blank as well as the for the terminating characters. This will serve the blue print of all your programs involving strings. Also remember extracting words from a string forms a vital tradition of ISC practical programs and I have used this logic in almost all my programs under the method name "wordExtractor()". You should be familiar with all the above mention methods very well! Any comment is always welcome :)