1001 A+B Format (20)(20 分)

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 9

Sample Output

-999,991

注意几个输出点:-991  991 1001 -1001
 #include<iostream>
#include <sstream>
#include<string>
#include<stack>
#include<typeinfo> using namespace std; int main()
{
int a,b,flag=,temp=; cin>>a>>b; a+=b; if(a<)
{
flag=;
cout<<"-";
} stringstream ss;
ss<<a; string str=ss.str(); stack<char> s; for(int i=str.length()-;i>=flag;--i)
{
s.push(str[i]);
++temp; if(temp%== && i->=flag)
s.push(',');
} while(!s.empty())
{
cout<<s.top();
s.pop();
} cout<<endl; return ;
}

最新文章

  1. ABP文档 - Javascript Api
  2. 重叠I/O模型
  3. Cwinux源码解析系列
  4. js之oop &lt;三&gt;属性标签
  5. 附带详细注释的log4net的app.config文件配置例子
  6. FJNU 1155 Fat Brother’s prediction(胖哥的预言)
  7. 3DES 加解密,对长度不限制
  8. Qt之运行一个实例进程
  9. BZOJ_1002_[FJOI2007]_轮状病毒_(递推+高精)
  10. js去除左右空格
  11. js获取智能机浏览器版本信息
  12. java布尔值进行and和or逻辑运算原理
  13. 虚函数&amp;多态
  14. jenkins+docker 持续构建非docker in docker jenkins docker svn maven
  15. 大文件视频断点续传插件resumabel.js,优化上传速度,缩短最后一片等待时长。
  16. echarts.js--前端可视化数据图形
  17. MVC设计模式思想及简单实现
  18. YARN的三种调度器的使用
  19. jdk环境变量的设置
  20. python字符串拼接

热门文章

  1. xdoj新生现场赛1269——带有限制条件的bfs 寻找最短路径
  2. linux下如何执行.sh文件 【转】
  3. vue的理解
  4. windows server 2008 R2 部署NFS,实现多台服务器间、客户端间的共享目录。
  5. java知识整理
  6. synchronized (string.intern())
  7. LeetCode - Is Graph Bipartite?
  8. ios-UITextView输入时,字数限制的倒数及对超出的字数进行截取并弹出提示框
  9. Easyui datagrid 去掉表头的checkbox复选框
  10. 【java编程】java中什么是bridge method(桥接方法)