代码如下:
#include <bits/stdc++.h>
using namespace std;
int s__(char c){
if(!(c >= 'a' && c <= 'z') || !(c == ' ')){
return 0;
}
if(c=='a'||c=='d'||c=='g'||c=='j' ||c=='m'||c=='p'||c=='t'||c=='w'||c==' '){
return 1;
}
if(c=='b'||c=='e'||c =='h'||c=='k'||c=='n'||c=='q'||c=='u'||c=='x'){
return 2;
}
if(c=='c'||c=='f'||c=='i'||c =='l'||c =='o'||c=='r'||c=='v'||c=='y'){
return 3;
}
if(c=='s'||c=='z'){
return 4;
}
}
int main(){
string s;
int cnt = 0;
getline(cin, s);
int n = s.size();
for(int i = 0; i <= n - 1; i++)
{
cnt += s__(s[i]) }cout << cnt;return 0;
}
求大佬帮改