PAT 甲级 1001 A+B Format

本文介绍了一种使用C++编程语言处理数字输出的方法,通过创建两个数组分别存储数字和逗号来实现易于阅读的输出格式。这种方法适用于需要格式化显示大数值的应用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

开两个数组,一个存数字,一个存逗号,一开始用递归快点写了,发现逗号不好处理改用2个数组做了
#include <iostream>
#include "cstring"
#include <stdio.h>
#include "iomanip"
#include "vector"
#include "cmath"
#include "stack"
#include "algorithm"
#include <math.h>
#include "map"
using namespace std;
int main()
{
 
 int a,b,t=0,tt=0;
 cin>>a>>b;
 a+=b;
 if(a<0)
    cout<<"-";
    a=abs(a);
    int *q=new int[10000001];//存逗号
    int *qq=new int[10000001];//存数字
    if(!a)
    cout<<a;
    else{
while(a)
{
    if(t==3)
    {
        q[tt]=1;
        t=0;
    }
    t++;
    qq[tt++]=a%10;
    a/=10;
}
for(int h=tt-1;h>=0;h--)
{


    cout<<qq[h];
    if(q[h]==1)
        cout<<",";
}
}
return  0;


}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值