1 条题解

  • 0
    @ 1970-6-4 12:08:05

    练40.3 ASCII码

    解题思路

    读T个ASCII数值,每个转char,依次连续输出组成完整文字。

    正确性说明

    计算规则直接来自题目定义。按所述顺序处理时,已完成部分的结果被准确保存在累加量、计数或当前状态中;下一步只加入新增贡献。最终得到完整要求的结果。

    易错点

    编码32本身输出一个空格;不能在字符之间额外插空格。

    复杂度

    时间O(T),空间O(1)。

    参考代码(C++11)

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int t;
        cin >> t;
        while (t--) {
            int x;
            cin >> x;
            cout << char(x);
        }
        cout << "\n";
        return 0;
    }
    
    • 1