47 lines
855 B
C++
47 lines
855 B
C++
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
const int N = 510;
|
|
string s[N];
|
|
|
|
bool check(string x) {
|
|
for (int i = 1; i < x.size(); i++)
|
|
if (x[i] < x[i - 1])
|
|
return false;
|
|
return true;
|
|
}
|
|
int main() {
|
|
freopen("Sample.in", "r", stdin);
|
|
|
|
int T;
|
|
cin >> T;
|
|
while (T--) {
|
|
int n;
|
|
cin >> n;
|
|
int res = 1;
|
|
for (int i = 1; i <= n; i++) {
|
|
cin >> s[i];
|
|
if (!check(s[i]))
|
|
res = 0;
|
|
}
|
|
if (res == 0) {
|
|
cout << 0 << endl;
|
|
continue;
|
|
}
|
|
sort(s + 1, s + n + 1);
|
|
|
|
for (int i = 2; i <= n; i++) {
|
|
// 当前串的头
|
|
char head = s[i][0];
|
|
// 前一个串的尾巴
|
|
char tail = s[i - 1][s[i - 1].size() - 1];
|
|
|
|
if (head < tail) {
|
|
res = 0;
|
|
break;
|
|
}
|
|
}
|
|
cout << res << endl;
|
|
}
|
|
|
|
return 0;
|
|
} |