C/C++基础语法练习 - ASCII码(新手推荐阅读✨)

题目链接:https://www.starrycoding.com/problem/159

题目描述

给一个仅包含大小写字母和数字的字符串,请输入它的每个字符对应的ASCII码。

输入格式

一行输入一个字符串 S ( 1 ≤ ∣ S ∣ ≤ 1000 ) S(1 \le |S| \le 1000) S(1S1000)

输出格式

一行内输出 ∣ S ∣ |S| S个数字( ∣ S ∣ |S| S为字符串长度),表示 n n n个字符的ASCII码。

输入样例1

StarryCoding2024

输出样例1

83 116 97 114 114 121 67 111 100 105 110 103 50 48 50 52

题解

用STL - string读取字符串并逐个遍历转化为int类型输出即可。

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll p = 1e9 + 7;
const int N = 1e5 + 9;

void solve()
{
    string s;
    cin >> s;
    for (const auto &i : s)
    {
        cout << (int)i << ' ';
    }
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    while (_--)
        solve();
    return 0;
}

在这里插入图片描述

提交记录:https://www.starrycoding.com/submission/5172

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-01 06:02:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-01 06:02:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-05-01 06:02:03       87 阅读
  4. Python语言-面向对象

    2024-05-01 06:02:03       96 阅读

热门阅读

  1. CSS三个标题及对应内容的tab切换

    2024-05-01 06:02:03       31 阅读
  2. python挑战10秒小程序

    2024-05-01 06:02:03       32 阅读
  3. C语言-宏定义2.0

    2024-05-01 06:02:03       39 阅读
  4. Rust 命令行参数解析指南

    2024-05-01 06:02:03       32 阅读
  5. 动态提示工具插件库——tippyjs

    2024-05-01 06:02:03       30 阅读
  6. wetrtc简介

    2024-05-01 06:02:03       33 阅读
  7. 微信小程序个人开放服务类目表

    2024-05-01 06:02:03       31 阅读
  8. 数据库学习之用户管理和权限问题

    2024-05-01 06:02:03       32 阅读
  9. 每日写题(第八天)

    2024-05-01 06:02:03       30 阅读