QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#219250 | #5666. Repetitive Elements | JenniferLing# | AC ✓ | 11ms | 3820kb | C++17 | 992b | 2023-10-19 10:09:33 | 2023-10-19 10:09:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
string s; cin >> s;
int n = (int)s.size();
string res = "";
auto chk = [&](string t, int len) {
int cnt = 0;
for (int i = 0; i <= n - len; i++) {
if (s[i] == t[0]) {
int flag = 1;
for (int j = 0; j < len; j++) {
if (s[i + j] != t[j]) {
flag = 0;
break;
}
}
if (flag) {
i += len - 1;
cnt++;
}
}
}
return cnt >= 2;
};
for (int l = 0; l < n; l++) {
for (int r = l; r < n; r++) {
if (r - l + 1 > n / 2) continue;
if (chk(s.substr(l, r - l + 1), r - l + 1)) {
if (r - l + 1 > (int)res.size()) {
res = s.substr(l, r - l + 1);
}
}
}
}
cout << res << "\n";
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
cin >> T;
while (T--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3820kb
input:
5 TATCGATCGAGTTGT TCCGCGAGCGAGTCTCTCCATT GTTTCATCATACGAGGCCCCATACGCGCTGG AGATGGGATCCTTATG GCCCTTAGGCATGGGATGTCGTTTCTTG
output:
ATCG GCGA CATACG GAT CTT
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 11ms
memory: 3608kb
input:
50 TTGACAACTTCAGGTTGGCACTCCTTCATTTGGATTTCGGAATAATAGTTTTCTGCTCTGCC ATCCTATTCGGGGATAGGAGAGATGGGTTGCCGCTATAAAAGCATTTGAACTCCATTTCACTCCGTTGGCTAGGGGTCGCACTG CCGTAATATAAAGACTCGGAATTCCAATAGCTGCTATTTGCGAGTATGTGACTGAAAACACACCTATAAATATTAGCTGCGTACAAGCTA ATGGCTGCATGCAGGGTCGACTAGACACACTTTGTCT TTGAGGATGTCGACGTGTCT...
output:
CTTCA CATTT TAGCTGC TGCA ACGTG GCGCCGG CTCTT AGTAT AGAG ACAG TAT TGAC CTTG CGTC TACTGG GCCGGT GAA CAGTA GCGT GGTT CCCT GAG TAGAC GGTGC GCAGT TGAG ATCAA CCACACA GAGTC ATGTA ATGGTA TATA TATGAA TTCC CATACG TACCA TTAG GGAATGT CAGG GCT AAG CTGT GGAT TCTTC AAAAC ATG GATAA TTA ACATAT CAAT
result:
ok 50 lines