-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrixSideView.java
64 lines (58 loc) · 1.15 KB
/
matrixSideView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
Matrix Side View
if given Character is l or L print 1 st alphabet from left to right else from right to left
I/P:
4 6
e - y - r k
- x i - - -
- - - a t q
- m - - p a
L
O/P:
exam
*/
import java.util.*;
public class Hello {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int r,c;
r=sc.nextInt();
c=sc.nextInt();
System.out.println(r+" "+c);
sc.nextLine();
String[][] a = new String[r][c];
for(int i=0;i<r;i++)
{
a[i]=sc.nextLine().split(" ");
}
char ch = sc.next().charAt(0);
if(Character.toLowerCase(ch)=='l')
{
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
if(Character.isLetter(a[i][j].charAt(0)))
{
System.out.print(a[i][j]);
break;
}
}
}
}
else if(Character.toLowerCase(ch)=='r')
{
for(int i=0;i<r;i++)
{
for(int j=c-1;j>=0;j--)
{
if(Character.isLetter(a[i][j].charAt(0)))
{
System.out.print(a[i][j]);
break;
}
}
}
}
}
}