【codechef】Strings Classes(枚举灵活题)

While developing Apps for Artificial Intelligence, Arush has to use specific type of strings (words) called Class C strings.
All the strings have been classified into 3 classes:

Class A : A sequence of letters that read the same forward and backward.

Class B : A string of class B can be converted to class A type by changing exactly one letter to a different letter.
For Example, CAT is class B type, since it can be changed to class A by either changing "C" to "T" or "T" to "C".

Note that "SEES" is not a class B type, since changing one letter would not make it to a class A type.

Class C : A string of class C is one that is formed by concatenating 2 strings of class B together. 

For example, BATMAN is a class C type, since BAT and MAN both belong to class B type.



Given a list of words, help Arush determine which words belong to class C type and which do not.

 

Input

  • Input will consist of all uppercase words which will not be more than 25 characters in length.
  • The last word will be *END* which is not to be processed, it is just to mark the end of input.

 

Output

  • For each input, output "INPUT_STRING YES" if it is a class C type otherwise "INPUT_STRING NO" (without quotes).

 

Constraints

  • 1 ≤ Length of each word ≤ 25

Example

Input:
BATMAN
SUPERMAN
*END*

Output:
BATMAN YES
SUPERMAN NO
http://www.codechef.com/CLCO2015/problems/CLCO07
判断一个字符串能否由两个ClassB的字符串拼成。ClassB:改一个位置刚好是回文串。这里要注意,如果一个字符串本来就是回文串,那么它是偶数的时候是不满足的,但是它是奇数的时候是满足的(可以改最中间那个,不影响)
#include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#define ll long long
#define FF(i, a, n) for (int i = a; i < n; i++) 
using namespace std; 
bool classb(string s){   //判断是不是符合ClassB
	int l = 0;
	int r = s.size() - 1;
	int c = 0;
	while (l < r) {
		if (s[l] != s[r]) {
			c++;
		} 
		l++;
		r--;
	}
	if (c > 1) return 0;
	if (c == 0) {
		if (s.size() % 2 == 0) return 0; //分类
		return 1;
	} 
	return 1;
}
bool fun(string l, string r){
	if (classb(l) && classb(r)) return 1;
	return 0;
} 
int main()
{
	while (1) {
		string s;
		cin >> s;
		if (s == "*END*") {
			break;
		}
		int f = 0;
 		for (int i = 0; i < s.size(); i++) {  //分割成两部分,枚举分割的位置
 			string l = "";
 			string r = "";
 			for (int j = 0; j <= i; j++) {
 				l += s[j]; 
 			}
 			for (int j = i + 1; j < s.size(); j++) {
 				r += s[j];
 			}
 			if (fun(l, r)) {
 				cout << s << " YES" << endl;
 				f = 1;
 				break;
 			} 
 		}
 		if (!f) {
 			cout << s << " NO" << endl;
 		}
 	}
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值