其他分享
首页 > 其他分享> > 题解 CF784D Touchy-Feely Palindromes

题解 CF784D Touchy-Feely Palindromes

作者:互联网

题目由此去


思路:输入的是字符串,然后转换成盲文,将盲文转换成 $ 1 $和 $ 0 $
,即将盲文中实心的点设成 $ 1 $,空心的设成 $ 0 $。然后这样判断回文就很方便了。

特别注意


代码如下:

#include <cstdio>
#include <cstring>
#include <iostream>
#define N 1000005

using namespace std;

string s;

int main() {
	cin >> s;
	int len = s.length();
	int a[len * 2 + 5], b[len * 2 + 5];
	for (int i=0, j=1; i<len, j<=len * 2; i++, j+=2 ) {
		if (s[i] == '1') {
			a[j] = 1;
			a[j + 1] = 0;
			b[j] = 0;
			b[j + 1] = 0;
		}
		if (s[i] == '2') {
			a[j] = 1;
			a[j + 1] = 0;
			b[j] = 1;
			b[j + 1] = 0;
		}
		if (s[i] == '3') {
			a[j] = 1;
			a[j + 1] = 1;
			b[j] = 0;
			b[j + 1] = 0;
		}
		if (s[i] == '4') {
			a[j] = 1;
			a[j + 1] = 1;
			b[j] = 0;
			b[j + 1] = 1;
		}
		if (s[i] == '5') {
			a[j] = 1;
			a[j + 1] = 0;
			b[j] = 0;
			b[j + 1] = 1;
		}
		if (s[i] == '6') {
			a[j] = 1;
			a[j + 1] = 1;
			b[j] = 1;
			b[j + 1] = 0;
		}
		if (s[i] == '7') {
			a[j] = 1;
			a[j + 1] = 1;
			b[j] = 1;
			b[j + 1] = 1;
		}
		if (s[i] == '8') {
			a[j] = 1;
			a[j + 1] = 0;
			b[j] = 1;
			b[j + 1] = 1;
		}
		if (s[i] == '9') {
			a[j] = 0;
			a[j + 1] = 1;
			b[j] = 1;
			b[j + 1] = 0;
		}
		if (s[i] == '0') {
			a[j] = 0;
			a[j + 1] = 1;
			b[j] = 1;
			b[j + 1] = 1;
		}
	}
	for (int i=1, j=len*2; i<=len, j>=len + 1; i++, j-- ) 
		if (a[i] != a[j] || b[i] != b[j]) {
			printf("No\n");
			return 0;
		}
	printf("Yes\n");
	return 0;
}

标签:CF784D,int,题解,len,第三行,盲文,字符串,Feely,include
来源: https://www.cnblogs.com/VenomCorrect/p/15193172.html