大神帮帮忙,为什么全WA?

P1765 手机

```cpp #include<iostream> #include<string> using namespace std; int a[]={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,1} ; int main() { string s; getline(cin,s); int k=0,l; l=s.size(); for(int i=0;i<l;i++) { if (s[i]==' ') k=k+1; else k=k+a[s[i]-'a']; } cout<<k; return 0; } ```
by 彭伏虎 @ 2019-03-17 21:33:55


```cpp #include<iostream> #include<string> using namespace std; int a[]={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,1} ; int main() { string s; getline(cin,s); int k=0,l; l=s.size(); for(int i=0;i<l;i++) { if (s[i]==' ') k=k+1; else if(s[i]>='a'&&s[i]<='z') k=k+a[s[i]-'a']; /*原来用的else就不行,改成else if就可以了!!!不是说只有小写字母和空格吗? */ } cout<<k; return 0; } ```
by 彭伏虎 @ 2019-03-17 21:44:48


看题解第一条= =
by syn666 @ 2019-03-17 22:57:48


@[彭伏虎](/space/show?uid=191352) 还有‘\n’和‘\r’,而且双if就行
by yc杨晨大家好 @ 2019-08-24 14:25:21


|