A+B Format
来源:互联网 发布:fc2live直播域名 编辑:程序博客网 时间:2024/06/05 22:45
Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).
Input
Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.
Output
For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.
Sample Input-1000000 9Sample Output
-999,991思路:利用一个字符数组2元素和的最小位到最高位,然后倒序输出,每次存了3个数字的时候,要加一个逗号。
#include<stdio.h>int main(){ int a,b,m,i=0,j=0; //m记录个位数 char out[20]; int flag=0; scanf("%d%d",&a,&b); int sum=a+b; if(sum<0) {flag=1; sum=-sum;} while(sum){ m=sum%10; sum=sum/10; out[j++]= m +'0'; i++; //i记录位数 if(i%3==0) out[j++]=','; } if(flag) printf("-"); if(out[j-1]==',') j--; //如果第一位是',',那么就不输出 for(;j>0;j--){ printf("%c",out[j-1]); } return 0;}
阅读全文
0 0
- 1001. A+B Format
- PAT1001.A+B Format
- A+B Format (20)
- PAT_1001: A+B Format
- PAT1001. A+B Format
- PAT1001. A+B Format .
- 1001.A+B Format
- 1001. A+B Format
- 1001. A+B Format
- A+B format
- 1001. A+B Format
- 1.A+B Format
- 1001. A+B Format
- 1001 A+B Format
- PAT1001. A+B Format
- A+B Format (20)
- 1001. A+B Format
- 1001. A+B Format
- IntelliJ IDEA 实用快捷键
- Matlab plot函数
- python字典
- es 基本语法 使用 案例
- mysql schema设计方法
- A+B Format
- 资讯精选 | 各国加强网络安全法规建设和隐私保护
- Android ORMLite框架笔记
- 关于接水问题心得
- jQuery基础(2)
- 自然语言处理(简称NLP)
- 如何清空<div>标签中的内容 而不清除<div>标签
- GHGL项目总结-DB2
- 从InnoDB了解MVCC