跳到正文

题解

题解:P1765 手机

Jayzx约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年6月30日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 1 分钟
获赞
17
题目
P1765

版本

  1. v1当前

打出每一个小写字母所要按的次数,枚举每一个字符,如果是空格就加一,否则从加上此字母要按的次数。时间复杂度 O(n)O(n)。

C++
#include<bits/stdc++.h>
using namespace std;
string a;
int ans,sum[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};
int main(){
    getline(cin,a);
    for(auto i:a) ans+=(i==' '?1:sum[i-'a']);
    printf("%d",ans);
}
原文
存档评论9 条抓取于