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;}