题是水题,但给人灵活使用数组的启发
如果刚学循环,那我肯定就一个劲的if if...了
但可以用数组把需要按下相同次数的字母(空格)放在一类,搜索的话就方便多了
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
getline(cin, str);
int n;
n = str.length();
char s1[]={" adgjmptw"},s2[]={"behknqux"},s3[]={"cfilorvy"},s4[]={"sz"};
int cnt = 0;
for (int i = 0; i < n; i++) {
if (strchr(s1,str[i])) {
cnt += 1;
}
if (strchr(s2,str[i])) {
cnt += 2;
}
if (strchr(s3,str[i])) {
cnt += 3;
}
if (strchr(s4,str[i])) {
cnt += 4;
}
}
cout<<cnt;
return 0;
}