题解
2026-05-09 16:59:57
发布于:上海
9阅读
0回复
0点赞
题目核心思路(超级简单)
这题只需要判断:所有字符需要移动的步数都必须一样!
两个字符串长度必须一样(题目已经保证)
计算第一个字符的偏移量 k
检查后面所有字符的偏移量是不是都等于这个 k
全部相同 → 输出 Yes,否则 No
C++ 代码(直接提交)
#include <iostream>
#include <string>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
// 计算第一个字符需要的 k
int k = (t[0] - s[0] + 26) % 26;
// 检查所有字符
bool ok = true;
for (int i = 0; i < s.size(); i++) {
int now = (t[i] - s[i] + 26) % 26;
if (now != k) {
ok = false;
break;
}
}
if (ok) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
这里空空如也






有帮助,赞一个