Posts

Showing posts from March 5, 2021

Submatrices - Diagonal Elements Sum :

Submatrices - Diagonal Elements Sum :  PROBLEM STATEMENT :   The program must accept an integer matrix M of size R*C and an integer N as the input. The program must print the sum of diagonal elements of all the N*N non-overlapping submatrices in M as the output.  Note: The value of N is always greater than 1 and less than or equal to the minimum value between R and C.  Boundary Condition(s):  2 <= R, C <= 50  0 <= Matrix element value <= 1000  Input Format:  The first line contains R and C separated by a space.  The next R lines, each contains C integer values separated by a space.  The (R+2)th line contains N.  Output Format:   The first line contains the integer values representing the sum of diagonal elements of all N*N non-overlapping submatrices in M.  Example Input/Output 1:  Input:  5 6  6 3 6 3 2 1 4 5 7 1 3 8 6 9 8 4 3 2  4 1 8 8 9 1  8 1 5 7 9 0  3  Output:  31...

Filling Holes with Wooden Sticks

Image
Filling Holes with Wooden Sticks  PROBLEM STATEMENT : SOLUTIONS : C (Programming Language) Copy Code #include<stdio.h> #include<stdlib.h> int main() { int r,c,i,j,n,k,flag=0; scanf("%d %d\n",&r,&c); char ch[r][c],s[2]; for(i=0;i<r;++i) { for(j=0;j<c;++j) { scanf("%s",s); ch[i][j]=s[0]; } } scanf("%d\n",&n); int x[n]; for(i=0;i<n;++i) { scanf("%d ",&x[i]); } for(j=0;j<c;++j) { i=0; while(i<r&&ch[i][j]=='*') i+=1; for(k=0;k<n;++k) { if(x[k]==i) { x[k]=-1; k=-1; break; } } if(k==-1) { i-=1; while(i>=0) { ch[i][j]='#'; i-=1; } } } ...