Forethought Future Cup 2019 Problem——B. Hate "A"——Codeforces

B. Hate “A”
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Bob has a string s consisting of lowercase English letters. He defines s′ to be the string after removing all “a” characters from s (keeping all other characters in the same order). He then generates a new string t by concatenating s and s′. In other words, t=s+s′ (look at notes for an example).

You are given a string t. Your task is to find some s that Bob could have used to generate t. It can be shown that if an answer exists, it will be unique.

Input

The first line of input contains a string t (1≤|t|≤105) consisting of lowercase English letters.

Output

Print a string s that could have generated t. It can be shown if an answer exists, it is unique. If no string exists, print “?” (without double quotes, there is no space between the characters).

Examples

input

aaaaa

output

aaaaa

input

aacaababc

output

?

input

ababacacbbcc

output

ababacac

input

baba

output

?

Note

In the first example, we have s= “aaaaa”, and s′= “”.

In the second example, no such s can work that will generate the given t.

In the third example, we have s= “ababacac”, and s′= “bbcc”, and t=s+s′= “ababacacbbcc”.

思路:

借鉴一个大佬的思路,string类型字符串先将去a后的存储在另一的char类型的数组中,接下来看char类型的字符串长度是否为偶数,如果是奇数就输出哭脸,偶数就看string类型的字符串的第string类型字符串长度减char类型的字符串的一半,与char类型的前一半进行比较,如果都一样输出,前string类型字符串长度减char类型的字符串长度的一半就行了,如果不然,输出哭脸。、

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define ll long long
#define mes(x,y) memset(x,y,sizeof(x))
using namespace std;
ll gar(ll a,ll b){//最大公约数 
return b==0?a:gar(b,a%b);
}
int main(){
	 string s;
	 while(cin>>s){
	 	char s1[1000000];int i=0,j=0,len=s.length(),k=0;
	 	for(;i<len;i++){
	 		if(s[i]!='a'){
	 			s1[j++]=s[i];
			 }
		 }//string类型字符串先将去a后的存储在另一的char类型的数组中
		 if(j%2!=0){
		 	cout<<":("<<endl;
		 	continue;
		 }//接下来看char类型的字符串长度是否为偶数,如果是奇数就输出哭脸
		 for(i=len-j/2;i<len;i++){
		 	if(s[i]==s1[k]){
		 		k++;
			 }
		 }/偶数就看string类型的字符串的第string类型字符串长度减char类型的字符串的一半,与char类型的前一半进行比较,
		 if(j/2==k)
		 {
		 	for(i=0;i<(len-j/2);i++){
		 		cout<<s[i];
			}
			cout<<endl; 
		 } //如果都一样输出,前string类型字符串长度减char类型的字符串长度的一半就行了
		 else{
		 	cout<<":("<<endl;
		 }//如果不然,输出哭脸。
	 } 
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GUESSERR

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值