PAT (Basic Level) Practise 的C++实现-1006. 换个格式输出整数

本文介绍了一种使用特定格式输出不超过三位的正整数的方法,并提供了完整的C++实现代码。该方法通过拆分百位、十位和个位数字,并用特定字符表示每一位上的数值。

让我们用字母B来表示“百”、字母S表示“十”,用“12…n”来表示个位数字n(<10),换个格式来输出任一个不超过3位的正整数。例如234应该被输出为BBSSS1234,因为它有2个“百”、3个“十”、以及个位的4。

输入格式:每个测试输入包含1个测试用例,给出正整数n(<1000)。

输出格式:每个测试用例的输出占一行,用规定的格式输出n。

输入样例1:
234
输出样例1:
BBSSS1234
输入样例2:
23
输出样例2:
SS123


#include <iostream>
#include <string>
using namespace std;

int main() {
    int i, sum, a1, a2, a3;
    cin >> sum;
    a1 = sum / 100;
    a2 = (sum%100)/ 10;
    a3 = (sum % 10);
    i = 0;
    while (a1-- != 0)
        cout << "B";
    while (a2-- != 0)
        cout << "S";
    while (a3-- != 0)
        cout << ++i;
    return 0;
}

尝试了一下类似于while(–a)这种写法,挺舒服的。

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project hertzbeat-otel: Compilation fai lure: Compilation failure: [ERROR] 读取C:\Users\DE-LL\.m2\repository\io\opentelemetry\opentelemetry-sdk-logs\1.49.0\opentelemetry-sdk-logs-1.49.0.jar时出错; zip file is empty [ERROR] /F:/Practise/hertzbeat-master/hertzbeat-otel/src/main/java/org/apache/hertzbeat/otel/config/OpenTelemetryLogbackAppenderInstaller.java:[19,1] 无 法访问org.apache.hertzbeat.otel.config [ERROR] ZipException opening "opentelemetry-sdk-logs-1.49.0.jar": zip END header not found [ERROR] /F:/Practise/hertzbeat-master/hertzbeat-otel/src/main/java/org/apache/hertzbeat/otel/config/LogAutoConfiguration.java:[34,8] 无法访问org.apache. hertzbeat.otel [ERROR] ZipException opening "opentelemetry-sdk-logs-1.49.0.jar": zip END header not found [ERROR] /F:/Practise/hertzbeat-master/hertzbeat-otel/src/main/java/org/apache/hertzbeat/otel/config/OpenTelemetryConfig.java:[50,8] 无法访问org.apache.h ertzbeat [ERROR] ZipException opening "opentelemetry-sdk-logs-1.49.0.jar": zip END header not found [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException [ERROR] [ERROR] After correcting the problems, you can resume the build with the command [ERROR] mvn <args> -rf :hertzbeat-otel 解决错误
最新发布
09-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值