PAT. advance level. T.1001. A+B format
来源:互联网 发布:淘宝助理如何删除宝贝 编辑:程序博客网 时间:2024/06/01 09:18
#include<stdio.h>main(){ long a,b,c,n,z,i,temp1,sum[10],temp2,temp3,temp4,temp5,temp6,test; c = 0; n = 0; z = 1; i = 0; temp1 = 1; temp2 = 0; temp3 = 0; temp4 = 0; temp5 = 0; temp6 = 0; scanf("%ld %ld",&a,&b); c = (a + b); test = c; if (c<0) { printf("-"); c = -c; n = c; }else { n = c; } while (c > 9){ c /= 10; z = z * 10; temp6++; } z = z * 10; temp6++; temp2 = temp6; while (n>9){ i = n % 10; n /= 10; sum[temp1] = i; temp1++; } sum[temp1] = n; temp3 = temp1 % 3; for (temp4=temp1;temp4>=1;temp4--){ if (test == 0){ printf("0"); break; } printf("%ld",sum[temp4]); if (((temp1-temp4+1) == temp3 )&&(temp3!=0)&&(temp1>3)){ printf(","); temp5 = 0; continue; } temp5++; if ((temp5 == 3)&&(temp4!=1)){ printf(","); } } return 0;}
先判断相加之和的正负,为0和负数的时候划分出来。
用数组将每一个数拆分出来,然后逆序,先%3,可以得出最前有几个数字就用逗号。最后输出。
0 0
- PAT. advance level. T.1001. A+B format
- PAT(Advanced level) 1001. A+B Format
- PAT(A-LEVEL) 1001 A+B Format
- PAT (Advanced Level) Practise 1001. A+B Format
- 【PAT Advanced Level】1001. A+B Format (20)
- 【c++】PAT (Advanced Level) 1001. A+B Format (20)
- 【PAT (Advanced Level)】1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- 浙大 PAT Advanced level 1001. A+B Format
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- PAT (Advanced Level) 1001. A+B Format (20) 解题报告
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- 【PAT】【Advanced Level】1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- PAT Advanced Level 1001:A+B Format
- PAT(Advanced Level) A+B Format
- Android中的MVVM
- greendao3.0以上使用步骤(二):数据库到底该怎么升级
- java集合类概要
- 算法开启的人工智能时代!阿里聚安全算法挑战赛公开报名!
- EventBus
- PAT. advance level. T.1001. A+B format
- EventBus3.0的使用
- slab源码分析--销毁函数
- NodeJS、NPM安装配置步骤(windows版本)
- docker基础知识命令
- EditText Cursor(游标)放置问题
- ubuntu14.04上装cmake3.2
- codeforces 8VC Venture Cup 2017 - Elimination Round D PolandBall and Polygon
- JQuery手势密码