-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGridChallenge.cpp
More file actions
53 lines (41 loc) · 848 Bytes
/
GridChallenge.cpp
File metadata and controls
53 lines (41 loc) · 848 Bytes
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
// problem: "https://www.hackerrank.com/challenges/grid-challenge/problem"
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int i,j,T,n;
char G[100][100],minr,minc;
cin>>T;
for(int k=0;k<T;k++)
{
cin>>n;
for(i=0;i<n;i++)
cin>>G[i];
for(i=0;i<n;i++)
sort(G[i],G[i]+n);
for(j=0;j<n;j++)
{
for(i=0;i<n-1;i++)
if(G[i][j]>G[i+1][j])
{
cout<<"NO"<<endl;
n=-1;
break;
}
if(n==-1)
break;
}
if(n!=-1)
cout<<"YES"<<endl;
}
/*
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
cout<<G[i][j];
cout<<endl;
}
*/
return 0;
}