其他字符算一个,贴下我的 #include <iostream> #include <vector> #include <string> #include <sstream> using namespace std; void getStringCount(string content){ bool isCharUpper = false; int count = 0; for(int i = 0;i < content.length();++i){ // if(!isalpha(content[i])) return;///非字母跳出 if(islower(content[i]) && isCharUpper){ if(i + 1 < content.length() && islower(content[i + 1])){ isCharUpper = false; count += 1;///按下caps }else{ count += 1;///按下shift } }else if(isupper(content[i]) && !isCharUpper){ if(i + 1 < content.length() && isupper(content[i + 1])){ isCharUpper = true; count += 1;///按下caps }else{ count += 1;///按下shift } } count += 1; } cout << count << endl; } int main() { int n; cin>>n; for(int i = 0;i < n;++i){ string str; cin>>str; getStringCount(str); } } </sstream></string></vector></iostream>