PAT甲题题解-1001. A+B Format (20)-字符串处理,水
2024-08-29 17:55:32
计算A+B的和,并且按标准格式处理,每3个就要有个逗号
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std; int main()
{
int a,b;
scanf("%d %d",&a,&b);
int sum=a+b;
char str[];
sprintf(str,"%d",sum); //将num按指定格式输入到str字符串中
int idx=;
if(sum<){
printf("-");
idx=;
}
int len=strlen(str);
for(int i=idx;i<len;i++){
printf("%c",str[i]);
int left=len-i-;
//剩下的个数是3的倍数的话,就要输出','。当然最后一位除外
if(left%== && i!=len-)
printf(",");
}
printf("\n");
return ;
}
最新文章
- 必杀技———SQL基础整理系列(一)
- navicat在ubuntu下中文乱码的真正解决方法ZT
- shell下的作业管理[转]
- weblogic性能调优参考
- JavaScript constructor 属性
- [Wordpress]Wordpress使用SMTP发送电邮
- SCVMM问题汇总
- css3 -&;gt; 多栏布局
- jQuery -&;gt; bind / live / delegate 终结者 - on
- python+appium使用记录
- iOS客户端开发与Web前端开发
- Python学习之一:Python2.7与opencv2.4安装配置
- 【leetcode78】Single Number II
- 携程Apollo一键编译脚本+部署实现
- Do You Kown Asp.Net Core -- Asp.Net Core 2.0 未来web开发新趋势 Razor Page
- Linux基础命令---ipcs显示进程通信
- Java:JavaBean和BeanUtils
- 记录一次.Net框架Bug发现和提交过程:.Net Framework和.Net Core均受影响
- Error starting ApplicationContext. To display the conditions report re-run your application with &#39;debug&#39; enabled.
- Emoji 编码