Acdream: acfun

Source: Internet
Author: User

Acfun


Time Limit: 2000/1000 ms (Java/others) memory limit: 128000/64000 KB (Java/others) submitstatisticnext problemproblem descriptionas a former acmer, "AC" is a special abbreviated word which can bring much pleasure to me. sometimes it means everything.
This problem is about "AC ".
One day, I write a long string s on the paper which contains "A" and "C ". now I want to find a lexicographic minimum string t satisfied that t is distinct with all substring of S. inputthe first line of input file contains an integer t indicating the number of case.
In each test case:
Input a string s consist of "A" and "C". The length of S is not large than 100. outputfor each test case:
You shoshould output the string t meet the condition. sample input
1ACAC
Sample output
AA

The meaning is to output the smallest Lexicographic Order, not the substring of the original string .. Find the longest consecutive a substring .. Because it does not belong to the original string, add a A after it.

Just give some data.

5

A

C

Aacaaa

Acaca

Cccaa


AA

A

Aaaa

AA

Aaa


#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<vector>#include<queue>using namespace std;int main(){    char str[108];    int ans;    int t;    scanf("%d", &t);    while( t-- )    {        scanf("%s", str);        int num=0;        ans=0;        for(int i=0; i<strlen(str); i++)        {            if(str[i]=='A')                    num++;            for(int j=i+1; j<strlen(str); j++)            {                if(str[j]=='A')                    num++;                if(str[j]!='A')                    break;            }            if(ans<num)               ans=num;            num=0;        }        for(int i=1; i<=ans+1; i++)            cout<<"A";        cout<<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.