Code with Vinay

ISC practical papers › ISC 2018 › Question 3

Vertical Banner

ISC 2018 Computer Science Practical, Question 3 · Strings

The question

The names of teams participating in a competition should be displayed on a banner vertically, to accomodate as many teams as possible in a single banner.
Design a program to accept the name of N teams, where 2<N<9 and display them in a vertical order, side by side with a horizontal tab (i.e. eight spaces).
Test your program for the following data and some random data:
Example 1:
INPUT: N=3
Team 1: Emus
Team 2: Road Rols
Team 3: Coyote
OUTPUT:
E    R    C m    o    o u    a    y s    d    o
         t
    R    e
    o
    l
    s

Example 2:

INPUT: N=4
Team 1: Royal
Team 2: Mars
Team 3: De Rose
Team 4: Kings
OUTPUT:
R    M    D    K o    a    e    i y    r         n a    s    R    g l        o    s
        s
        e
Example 3:
INPUT: N=10
OUTPUT:
INVALID INPUT

Question: ISC 2018 Computer Science Paper 2 (Practical), Question 3, set by the Council for the Indian School Certificate Examinations (CISCE). Solution and video: Vinay Singh.

Java solution

ISC2018Q3.java Download GitHub
import java.util.*;
public class ISC2018Q3 {
    public static void main(String[] args) {
        Scanner in = new Scanner( System.in );
        System.out.print("INPUT: N = ");
        int N=in.nextInt();
        in.nextLine();
        if( N>2 && N<9 ){
            int max=0;
            String team[]=new String[N];
            for( int i=0; i<N; i++){
                System.out.print("Team "+(i+1)+": ");
                team[i]=in.nextLine();
                if(team[i].length()>max) max=team[i].length();
            }
            System.out.println("OUTPUT");
            for( int row=0; row<max;row++){
                for( int col=0; col<N;col++){
                    if(row<team[col].length()){
                        System.out.print(team[col].charAt(row)+"\t");
                    }else{
                        System.out.print("\t");
                    }
                }
                System.out.println();
            }
        }else{
            System.out.println("OUTPUT:\nINVALID INPUT");
        }
        in.close();
    }
}

All these solutions in one free book

Pragmatic Solutions to ISC Computer Science Practical Problems collects every program from 2004 to 2021 in a 202-page PDF.

Get the free PDF ₹0 ISC 2027 mock papers