跳到正文

题解

P1765 手机

nightwatch.ryan约 1 分钟
原文
文章信息与版本

文章信息

发布
2023年7月10日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 1 分钟
获赞
2

版本

  1. v1当前

思路

首先用 getline()getline() 读入一个字符串,然后循环判断字符串里的每一个字母,用 cntcnt 存储答案,最后输出

Code

C++
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int cnt=0;
   string str;
   getline(cin,str);
   int len;
   len=str.size();
   for(int i=0;i<len;i++)
   {
   	if(str[i]=='a'||str[i]=='d'||str[i]=='g'
   	||str[i]=='j'||str[i]=='m'||str[i]=='p'
   	||str[i]=='t'||str[i]=='w'||str[i]==' ')
   	{
   		cnt+=1;
   	}
   	if(str[i]=='b'||str[i]=='e'||str[i]=='h'
   	||str[i]=='k'||str[i]=='n'||str[i]=='q'
   	||str[i]=='u'||str[i]=='x')
   	{
   		cnt+=2;
   	}
   	if(str[i]=='c'||str[i]=='f'||str[i]=='i'
   	||str[i]=='l'||str[i]=='o'||str[i]=='r'
   	||str[i]=='v'||str[i]=='y')
   	{
   		cnt+=3; 
   	}
   	if(str[i]=='s'||str[i]=='z')
   	{
   		cnt+=4; 
   	}
   }
   cout<<cnt;
   return 0;
}
原文
存档评论2 条抓取于