Breaking

Friday 28 July 2017

Word Slot

                             Word Slot
                               


A Square Matrix of N Rows and N Columns is passed as the input and also a String S of Length L is passed as input. The matrix has an empty slot of length L denoted by + and remaining cells are denoted by #, with a space separating them.
Example of a slot of length 3 in the first row starting from column 2 and ending at column 4:
# + + + #
# # # # #
# # # # #
# # # # #
# # # # # 
Input Format:
First line contains N.
Next N lines contain the matrix cell values as described above.
The final line contains S
Output Format:
Matrix is printed with the empty cell slots denoted by + filled with the characters in string S.
Boundary Conditions:
1 <= N <= 100
1 <= Length of S <= 100

Example Input/Output 1:
Input:
5
# # + # #
# # + # #
# # + # #
# # + # #
# # + # #
India
Output:
# # I # #
# # n # #
# # d # #
# # i # #
# # a # #
Example Input/Output 2:
Input:
3
# + +
# # #
# # #
Hi
Output:
# H i 
# # # 
# # # 

Code:

#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
char arr[100][100];
int i,j,n;
cin>>n;
for(i=0;i<n;i++)
    for(j=0;j<n;j++)
        cin>>arr[i][j];
char ch[100];
    cin>>ch;
int k=0;
for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
            {
                if(arr[i][j]=='+')
                    cout<<ch[k++]<<" ";
                else
                    cout<<arr[i][j]<<" ";
            }
        cout<<"\n";
    }
}
#V2 #v2lancers

No comments:

Post a Comment

Like