Description
As 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.
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.
Input
The 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.
In each test case:
Input a string S consist of "A" and "C". The length of S is not large than 100.
Output
For each test case:
You should output the string T meet the condition.
You should output the string T meet the condition.
Sample Input
1 ACAC
Sample Output
AA
自己写的略麻烦啊。。。
#include <stdio.h>
#include <string.h>
#define N 105
char a[N];
int b[N];
int main() {
int n;
scanf("%d\n", &n);
while (n--) {
gets(a);
int t = 0;
for (int i = 0; i < strlen(a); i++)
if (a[i] == 'A')
b[t++] = i;
int index = 0, max = 0;
for (int j = 0; j < t; j++) {
if (j == 0) {
index++;
max = index;
continue;
}
if (b[j] == b[j-1] + 1) {
index++;
if (index > max)
max = index;
}
else
index = 1;
}
for (int i = 0; i <= max; i++)
printf("A");
printf("\n");
}
return 0;
}
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define N 100
char str[N];
int main() {
int n;
scanf("%d", &n);
while (n--) {
gets(str);
int len = strlen(str), index = 0, maxx = 0;
for (int i = 0; i < len; i++) {
if (str[i] == 'A')
index++;
else {
maxx = max(index, max);
index = 0;
}
}
maxx = max(maxx, index);
for (int i = 0; i <= maxx; i++)
printf("A");
printf("\n");
}
return 0;
}