#include using namespace std;

int main() { int n; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; int len = s.size(); int i = 0, j = len - 1; bool isBeautiful = true; while (i <= j) { if (s[i] == s[j] + 1) { i++; } else if (s[i] + 1 == s[j]) { j--; } else { isBeautiful = false; break; } } if (isBeautiful) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; }

C++ 判断漂亮串:双指针算法优化

原文地址: https://www.cveoy.top/t/topic/pPmO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录