1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| #include<iostream> using namespace std; int main(){ string i; int num[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},ans=0; getline(cin,i); for(int s=0;s<i.length();s++){ if(i[s]>='a'&&i[s]<='z'){ ans+=num[i[s]-'a']; } if(i[s]==' '){ ans++; } } cout<<ans<<endl; }
|