#include <bits/stdc++.h> using namespace std; int main() { string s; int k[26] = {1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 1, 2, 3, 4}; while (cin >> s) { int count = 0 ; for (int i = 0 ; i < s.length() ; i++) { if (i != 0 and s[i] - s[i - 1] == k[s[i] - 'a'] - k[s[i - 1] - 'a']) count = count + 2; count = count + k[s[i] - 'a']; } cout << count << endl; } }
这个条件有点难思考:s[i] - s[i - 1] == k[s[i] - 'a'] - k[s[i - 1] - 'a'])
只想到了s[i] - s[i - 1] == 0