UVA 11512--gattaca

Source: Internet
Author: User

Test instructions: Gives a string that repeats the maximum length of the string and repeats the number of repetitions (in length), when there are two lengths of the same substring that are the output dictionary order small substring.

Example: Gagagag maximum repeat substring is gagag number of times is 2

Analysis: Two points + violence map

Determine whether a string of length k has a repeating string, the existence of a longer string is discussed, and a shorter string is discussed if it does not exist.

Time:160ms (SKY)

#include <bits/stdc++.h> using namespace std;
int t;
String str,s;
int Len;
unordered_map<string,int>temp;
set<string>check;
    int judge (int mid)//Determine if there is a duplicate string {temp.clear ();
    Check.clear ();
        for (int j=0; j<=len-mid; J + +) {s=str.substr (j,mid);
        temp[s]++;
        if (temp[s]==2) {Check.insert (s);
    }} if (Check.empty () ==0) {return 1;
} return 0;
    } int main () {Ios::sync_with_stdio (false);
    Cin.tie (0);
    Cout.tie (0);
    cin>>t;
        while (t--) {temp.clear ();
        Check.clear ();
        cin>>str;
        Len=str.size ();
            int left=1,right=len-1;//binary finds the length of the string while (right-left>3) {int mid= (left+right)/2;
            if (judge (mid)) {Left=mid;
            } else {right=mid;
        }} int ans=left; for (int i=left; i<=righT
            i++) {if (judge (i)) {ans=i; }} int K=judge (ANS);//Determine length ans for maximum length if (Check.empty () ==1) {cout<< "No rep Etitions found! "
        <<endl; } else {s=*check.begin ();//set containers are sorted from small to large, with the smallest beginning cout<<s<< "" <<
        temp[s]<<endl;
}} return 0;
 }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.