P1765 手机
题目如下:
思路:
1.输入完成后会按enter 要记得\n也会被计入数字喔!
代码:
#include<cstdio> #include<cstring>> #include<iostream> using namespace std; int main(){ string ss; getline(cin,ss); int sum=0; int len=ss.size(); int a[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}; for(int i=0;i<len;i++){ if(ss[i]>='a'&&ss[i]<='z') sum+=a[ss[i]-'a']; else if(ss[i]==' ') sum+=1; } cout<<sum; return 0; } //i have a dream //3+1+2+1+3+2+1+1+1+1+3+2+1+1= 23
无聊就学习 反正没事干