0% found this document useful (0 votes)
41 views1 page

Cse Coides

This document contains descriptions of two problems to solve: 1) A program that takes a string as input and returns the shortest palindrome string that has the input as a prefix. 2) A program that takes a 2D array as input, prints the sum of the diagonals from top-left to bottom-right, and the total sum of all elements. The input specifies the array size n first, then provides the n^2 elements in row-major order.

Uploaded by

HYDRA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views1 page

Cse Coides

This document contains descriptions of two problems to solve: 1) A program that takes a string as input and returns the shortest palindrome string that has the input as a prefix. 2) A program that takes a 2D array as input, prints the sum of the diagonals from top-left to bottom-right, and the total sum of all elements. The input specifies the array size n first, then provides the n^2 elements in row-major order.

Uploaded by

HYDRA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Online (String, 2D array)

Time: 50 min, Marks: 20


Problem 1 (10 marks)
Write a program that will take a string s as input, and construct a string of shortest length
which is palindrome and contains s as a prefix.

Sample Input Sample Output


abcde abcdedcba
aba aba
abcb abcba

Problem 2 (10 marks)


A two dimensional array can be viewed as a matrix, which has diagonals in two
directions. We are concerned with the primary diagonals (top left to bottom right).
Write a program that will take an × array as input, and you will have to print sum of
all elements along such diagonals. For examples, for the following input 1st output is 3,
second output is 2+6=8, 3rd is 1+5+9=15, and so on.
Also print the summation of all elements in the matrix by summing the diagonals.
The first line of input is the value of n. Next numbers constructs the array in row
major order.
Sample Input Sample Output
3 3
123 8
456 15
789 12
7
45

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy