. Remove all the blank spaces between
character.Matrix is of 10* 10.
eg: INPUT
------------------------------------
| N | A | | V | |T
-------------------------------------
| |G | U | |P |
--------------------------------------
|T | | | A | |
------------------------------------
OUTPUT:
------------------------------------
| N | A | V | T | |
-------------------------------------
|G |U | P | | |
--------------------------------------
|T | A | | | |
------------------------------------

Answers were Sorted based on User's Feedback



. Remove all the blank spaces between character.Matrix is of 10* 10. eg: INPUT -----------..

Answer / indrasen singh

follow these steps..
a) Create 10 by 10 matrix of char array and fill with '|'

b) Now in a loop check your first matrx whether it have alphabet character if found then insert it into the new matrix in the desired position....

char str1[10][10] // suppose it contains your data
char str2[10][10] //it store result

int i,j;

for(i=0;i<10;i++)
for(j=0;j<10;j++)
str2[j]='|';

int charfound;

for(i=0;i<10;i++)
{
charfound=0;
for(j=0;j<10;j++)
{
if(isalpha(str1[j]))
{
charfound++;
str2[((charfound*2)-1)]=str1[j];
}
}
}

Is This Answer Correct ?    1 Yes 5 No

. Remove all the blank spaces between character.Matrix is of 10* 10. eg: INPUT -----------..

Answer / kiran

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package removespacesfrommatrix;

/**
*
* @author Sunshine
*/
public class RemoveSpacesFromMatrix {

void print(char[][] matrix) {
char temp;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (matrix[i][j] != ' ') {
System.out.println(matrix[i][j]);
} else {
temp = matrix[i][j + 1];
matrix[i][j] = temp;
matrix[i][j + 1] = ' ';
System.out.println(matrix[i][j]);
}
}
}
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
char[][] matrix;
matrix = new char[][]{{'a', 'b', ' ', 'c'}, {' ', 'd', ' ', 'f'}, {' ', ' ', 'x', 'y'}, {'m', 'n', 'o', 'p'}};
RemoveSpacesFromMatrix r = new RemoveSpacesFromMatrix();
r.print(matrix);
}
}

Is This Answer Correct ?    0 Yes 4 No

Post New Answer

More C++ Code Interview Questions

Min-Max Write an algorithm that finds both the smallest and largest numbers in a list of n numbers and calculate its complexity T(n).

1 Answers   Infosys, Qatar University,


Write a program that print in screen a tree with its height taken from user by entering number of 4 digits and find the odd numbers then calculate the sum of odd numbers so he get the height of tree?

0 Answers  


Code for Two Classes for Doing Gzip in Memory?

0 Answers  


write a program that accepts a number and outputs its equivalent in words. take note that the maximum input is 3000

1 Answers   Alvin,


What output does this program generate as shown? Why? class A { A() { cout << "A::A()" << endl; } ~A() { cout << "A::~A()" << endl; throw "A::exception"; } }; class B { B() { cout << "B::B()" << endl; throw "B::exception"; } ~B() { cout << "B::~B()"; } }; int main(int, char**) { try { cout << "Entering try...catch block" << endl; A objectA; B objectB; cout << "Exiting try...catch block" << endl; } catch (char* ex) { cout << ex << endl; } return 0; }

0 Answers  






. Remove all the blank spaces between character.Matrix is of 10* 10. eg: INPUT ------------------------------------ | N | A | | V | |T ------------------------------------- | |G | U | |P | -------------------------------------- |T | | | A | | ------------------------------------ OUTPUT: ------------------------------------ | N | A | V | T | | ------------------------------------- |G |U | P | | | -------------------------------------- |T | A | | | | ------------------------------------

2 Answers   Nagarro,


An array of size 5X5 is given to us. The elements from 1 to 25 are to be inserted in the array, such that starting from a particular position for an element i, the next element i+1can be inserted only at the mentioned positions (u,v), and if these all positions are occupied then it returns giving a count of how many positions have been occupied in the array: (u,v) = (x+/-3 , y) (u,v) = (x , y+/-3) (u,v) = (x+/-2 , y+/-2). Example: if the starting element is 1 with the given positions (1,2), then next element 2 can be placed at any one of the positions marked with *. _ _ _ _ _ 1 _ _ _ * _ _ _ _ _ _ _ * _ _ * _ _ _ _

0 Answers   Nagarro,


Question 1: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date. *This Should Be Done IN C++

0 Answers  


How to Split Strings with Regex in Managed C++ Applications?

0 Answers   Microsoft,


write a program that can LOCATE and INSERT elements in array using c++ programming languages.

0 Answers  


Write a program to enter 10 number of integer entries into an array n and then odds up all the odd entries. the program then displays the result. plssss answer assss fast asss u can...

1 Answers  


A string of charaters were given. Find the highest occurance of a character and display that character. eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE OUTPUT: E

1 Answers  


Categories