QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#278842#5666. Repetitive Elementsdat#AC ✓1ms3552kbC++171.5kb2023-12-07 21:18:092023-12-07 21:18:10

Judging History

你现在查看的是最新测评结果

  • [2023-12-07 21:18:10]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3552kb
  • [2023-12-07 21:18:09]
  • 提交

answer

#ifdef LOCAL
#include "precompiled_headers.h"
#else
#include <bits/stdc++.h>
#endif

using namespace std;

string mul_k(string s, int k) {
    string res;
    for (int i=1; i<=k; i++) {
        res += s;
    }
    return res;
}

int main() {
    std::ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;

    for (int i=1; i<=n; i++) {
        string s;
        cin >> s;

        int max_val = 0;
        int max_start, max_len;
        for (int i=0; i<s.length(); i++) {
            for (int j=0; j<s.length(); j++) {
                if (i != j && s[i] == s[j]) {
                    int start_i = i;
                    int start_j = j;
                    int curr_i = start_i;
                    int curr_j = start_j;
                    while (curr_i < start_j && curr_i < s.length() && curr_j < s.length() && s[curr_i] == s[curr_j]) {
                        curr_i++;
                        curr_j++;
                    }
                    if (curr_i - start_i > max_val) {
                        max_val = curr_i - start_i;
                        max_start = start_i;
                        max_len = max_val;
                    }
                }

            }
        }
        string ss;
        for (int i=0; i<max_val; i++) {
            ss += s[max_start + i];
        }

        cout << ss << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3552kb

input:

5
TATCGATCGAGTTGT
TCCGCGAGCGAGTCTCTCCATT
GTTTCATCATACGAGGCCCCATACGCGCTGG
AGATGGGATCCTTATG
GCCCTTAGGCATGGGATGTCGTTTCTTG

output:

ATCG
GCGA
CATACG
GAT
CTT

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 3548kb

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