1001. A+B Format (20)
来源:互联网 发布:java德州扑克牌比大小 编辑:程序博客网 时间:2024/06/06 02:06
题目:https://www.patest.cn/contests/pat-a-practise/1001
注意:sprintf的使用
#include<string.h>#include<stdio.h>#include<stdlib.h>using namespace std;int a,b,sum=0;char str[30];int main(){int st=0;int mod,y,len=0;scanf("%d%d",&a,&b);sum = a+b;sprintf(str,"%d",sum);len = strlen(str);if(str[0]=='-'){printf("-");st = 1;len = len-1;}mod = (len)%3;y = (len)/3;if(st == 0){for(int i=0; i<mod; i++){printf("%c",str[i]);st++;}}else{for(int i=1; i<=mod; i++){printf("%c",str[i]);st++;}}if(y>0&&mod>0)printf(",");for(int i=0; i<y; i++){if(i == y-1)printf("%c%c%c",str[st],str[st+1],str[st+2]);elseprintf("%c%c%c,",str[st],str[st+1],str[st+2]);st += 3;}return 0;}
0 0
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- UMEditor文本编辑器的使用
- Eclipse代码着色
- 大数据Java基础系列-Java基本数据类型
- python通过cx_Oracle模块连接Oracle乱码问题
- 剑指offer-判断树是否对称
- 1001. A+B Format (20)
- Windows下使用WSRM限制MongoDB内存
- 数据挖掘算法
- 关于ubantu在VMWARE里安装时出现'SMBus Host Controller not enabled'
- 夏天地板保养的注意事项
- iOS——UISegmentControl
- linux常用命令
- 485布线的要求
- Android 内存优化总结&实践