跳到正文

题解

题解:P13419 [COCI 2012/2013 #6] BAKA

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

文章信息

发布
2025年7月23日
收录
2026年11月28日
更新
2026年11月28日
篇幅
约 1 分钟
获赞
2
题目
P13419

版本

  1. v1当前

水。

我们先考虑如何将字母转成数字,设当前字符在英语字母表中的编号减 11 为 cc,数字为 xx:

  • 当 0≤c≤170 \leq c \leq 17(即字母在 A 到 R 范围内)时,x=⌊c3⌋+1x=\lfloor \frac{c}{3} \rfloor+1;
  • 当 17<c≤2417 < c \leq 24(即字母在 S 到 Y 范围内)时,x=⌈c3⌉+1x=\lceil \frac{c}{3} \rceil+1;
  • 当 c=25c=25 时,x=9x=9。

拨数字 11 需要 22 秒,拨更大的数字则每增加一个数字(从 11 到所拨数字),总时间再增加 11 秒。

因此拨一个数字所需要的时间就是 x+1x+1 秒。

实现时遍历字符串的每一个字符即可。

C++
#include <cstdio>
#include <cctype>
char s[114];
int main() {
    fgets(s, 114, stdin);
    int ans = 0;
    for (int i = 0; isalpha(s[i]); ++i) {
        int si = s[i] - 'A';
        if (si <= 'R' - 'A') ans += si / 3 + 3;
        else if (si <= 'Y' - 'A') ans += (si + 2) / 3 + 2;
        else ans += 10;
    }
    printf("%d", ans);
}
原文
抓取于
  1. ycy25

    %%%