QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#102482#5666. Repetitive Elementsir101#AC ✓32ms3464kbC++171.3kb2023-05-03 13:49:072023-05-03 13:49:09

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-03 13:49:09]
  • 评测
  • 测评结果:AC
  • 用时:32ms
  • 内存:3464kb
  • [2023-05-03 13:49:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
const int N=2e5+5,INF=0x3f3f3f3f,Mod=1e6;

const double eps=1e-6;
typedef long long ll;

int chaxun(string s,string sub){
    int idx = 0;        //开始查找的下标 & 找到子串的首字母下标
    int cnt = 0;        //子串出现次数
    //s.find(sub, idx)从s的idx处开始查找sub
    while ((idx = s.find(sub, idx)) != s.npos){
        idx++;
        cnt++;
    }
    return cnt;

}
int t;
string s;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>t;
    while(t--){
        cin>>s;
        bool ok=false;
        string res;
        //unordered_map<string,int>mp;
        for(int i=s.size()-1;i>=1;--i){
            for(int j=0;j+i-1<s.size();++j){
                string a=s.substr(j,i);
                for(int k=0;k+i-1<s.size();++k){
                    if((k<j&&k+i-1>=j)||(k+i-1>j&&k<=j+i-1))continue;
                    string b=s.substr(k,i);
                    if(b==a){
                        ok=true;res=a;break;
                    }
                }
                if(ok)break;
            }
            if(ok)break;
        }
        cout<<res<<'\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3400kb

input:

5
TATCGATCGAGTTGT
TCCGCGAGCGAGTCTCTCCATT
GTTTCATCATACGAGGCCCCATACGCGCTGG
AGATGGGATCCTTATG
GCCCTTAGGCATGGGATGTCGTTTCTTG

output:

ATCG
GCGA
CATACG
GAT
CTT

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 32ms
memory: 3464kb

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