2023.2.2(总结)

凯子,博子,静子是非常要好的伙伴,这一天博子和静子给凯子取了一个外号叫a,凯子和静子给博子取了一个外号b,凯子和博子又给静子取了一个外号c.

外号a,b,c都是由字符'a'和字符'b'组成的字符串,为了纪念他们的友好友谊,他们按照a,b,c的顺序把各自的外号写到了一起,因为他们的友谊实在是太好了,所以各自的外号写的几乎没有间隔,多年以后他们回到这里,再次看到这一串由a,b,c组成的字符串s的时候,谁也不知道谁的外号是什么了,模糊的记得当年的三个外号满足以下两个条件中的一个:

一.a的字典序小于等于b的字典序并且b的字典序大于等于c的字典序

二.a的字典序大于等于b的字典序并且b的字典序小于等于c的字典序

现在问你当年凯子,博子,静子的外号可能是什么

Input

第一行给定一个t(1<=t<=500)表示t组样例

对于每一组样例给定一个字符串s(3<=|s|<=100),字符串s由字符'a'和'b'构成

Each test contains multiple test cases. The first line contains the number of test cases tt (1 \le t \le 5001≤t≤500). The description of the test cases follows.

The only line of a test case contains the string ss (3 \le |s| \le 1003≤∣s∣≤100) — the names of the capybaras, written together. The string consists of English letters 'a' and 'b' only.

It is guaranteed that the sum of string lengths over all test cases does not exceed 500500.

Output

对于每组样例打印满足题意的a,b,c在一行,中间用空格隔开,如果有多组a,b,c满足题意,任意输出一种即可

For each test case, print three strings aa, bb and cc on a single line, separated by spaces — names of capybaras, such that writing them without spaces results in a line ss. Either a \le ba≤b and c \le bc≤b, or b \le ab≤a and b \le cb≤c must be satisfied.

If there are several ways to restore the names, print any of them. If the names cannot be recovered, print ":(" (without quotes).

Sample 1

InputcopyOutputcopy
5
bbba
aba
aaa
abba
abbb
b bb a
a b a
a a a
ab b a
a bb b

Note

A string xx is lexicographically smaller than a string yy if and only if one of the following holds:

  • xx is a prefix of yy, but x \ne yx=y;
  • in the first position where xx and yy differ, the string xx has the letter 'a', and the string yy has the letter 'b'.

Now let's move on to the examples.

In the first test case, one of the possible ways to split the line ss into three lines — "b", "bb", "a".

In the third test case, we can see that the split satisfies two conditions at once (i. e., a \le ba≤b, c \le bc≤b, b \le ab≤a, and b \le cb≤c are true simultaneously).

分析:

1,刚看见这个题目的时候我信心满满,因为按照我的预想因为是可以的。

2,然后我就开始了找b,因为我个人觉得只要找出了b,就可以划分成三部分。

3,然后就一直错,一直错,后来就换成了找a,然后就对了,其实我还是有点想不明白为什么找a可以,找b不可以的。

代码如下:

#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        char a[200005]={0},b[200005]={0};
        scanf("%s",a);
        int f=0;
        for(int j=1;j<strlen(a)-2;j++)
        {
            if(a[j]=='a')
            {f=j;break;}
        }
        if(f)
        {
            strcpy(b,a);
            b[f]='\0';
            printf("%s ",b);
            printf("a ");
            printf("%s\n",a+f+1);
        }
        else 
        {
            printf("%c ",a[0]);
            strcpy(b,a+1);
            b[strlen(a)-2]='\0';
            printf("%s ",b);
            printf("%c\n",a[strlen(a)-1]);
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值