#include <bits/stdc++.h> using namespace std; int dp[55][2]; int main() { ios::sync_with_stdio(false); cin.tie(0); string str; cin >> str; int len = str.length(); dp[0][0] = str[0] == 'R' ? 0 : 1; dp[0][1] = str[0] == 'R' ? 1 : 0; for (int i = 1; i < len; ++i) { dp[i][0] = dp[i-1][0] + (str[i] == 'R' ? 0 : 1); dp[i][1] = min(dp[i-1][1], dp[i-1][0]) + (str[i] == 'R' ? 1 : 0); } cout << min(dp[len-1][0], dp[len-1][1]) << endl; return 0; }ac代码...有很多情况的....