C++语言: Codee#25842
01 /*
02 +++++++++++++++++++++++++++++++++++++++
03                 author: chm
04 +++++++++++++++++++++++++++++++++++++++
05 */
06
07 #include <map>
08 #include <set>
09 #include <list>
10 #include <queue>
11 #include <cmath>
12 #include <stack>
13 #include <bitset>
14 #include <cstdio>
15 #include <cctype>
16 #include <string>
17 #include <vector>
18 #include <cassert>
19 #include <cstdlib>
20 #include <cstring>
21 #include <fstream>
22 #include <sstream>
23 #include <iomanip>
24 #include <iostream>
25 #include <algorithm>
26
27 using namespace std;
28
29 FILE*            fin         = stdin;
30 FILE*            fout         = stdout;
31 const int        max_size     = 10086;
32 #define ONLINE_JUDGE
33 int main()
34 {
35 #ifndef ONLINE_JUDGE
36     freopen("d:\\in.txt", "r", stdin);
37     freopen("d:\\out.txt", "w", stdout);
38 #endif
39     int a, b;
40     int sum;
41     int isneg = 0;
42     char str[max_size];
43     char ans[max_size];
44
45     while(cin >> a >> b)
46     {
47         isneg = 0;
48         if((sum = a + b) < 0)
49         {
50             sum *= -1;
51             isneg = 1;
52         }
53         sprintf(str, "%d", sum);
54         int idx = 0;
55         if(isneg)
56             cout << '-';
57
58         for(int i = strlen(str), j = 1; j<=i;++j)
59         {
60             cout << str[j - 1];
61             if((i - j) % 3 == 0 && i - j != 0)
62                 cout << ',';
63         }
64         cout << endl;
65     }
66
67 #ifndef ONLINE_JUDGE
68     fclose(stdout);
69     system("start d:\\check.exe d:\\out.txt d:\\ans.txt");
70 #endif
71     return 0;
72 }

转载于:https://www.cnblogs.com/invisible/archive/2012/03/16/2400337.html

1001. A+B Format相关推荐

  1. Pat甲级 1001 A+B Format

    Pat甲级 1001 A+B Format 思路 代码 题目网址 https://pintia.cn/problem-sets/994805342720868352/problems/99480552 ...

  2. PAT甲级1001 A+B Format:[C++题解]字符串处理

    文章目录 题目分析 题目链接 题目分析 数字转化成string 的函数to_string() 倒序遍历string,还保证原来的顺序需要 res = num[i] +res. 这里的加号不是数字运算, ...

  3. 【PAT甲】1001 A+B Format (20分) 格式化输出

    problem 1001 A+B Format (20分) Calculate a+b and output the sum in standard format – that is, the dig ...

  4. 题目1001 A+B Format

    记录学习写博客的第一天(PAT题目) 题目1001 A+B Format Calculate a+b and output the sum in standard format – that is, ...

  5. PAT-PAT (Advanced Level) Practise 1001. A+B Format (20) 【二星级】

    题目链接:http://www.patest.cn/contests/pat-a-practise/1001 题面: 1001. A+B Format (20) Calculate a + b and ...

  6. 1001 A+B Format (20分)——12行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Calculate a+b and output the sum in standard format – that is, th ...

  7. 1001 A+B Format (20point(s))(Java和C++)

    文章目录 Java版 C++版 Calculate a+b and output the sum in standard format – that is, the digits must be se ...

  8. PAT (Advanced Level) Practise:1001. A+B Format

    [题目链接] Calculate a + b and output the sum in standard format -- that is, the digits must be separate ...

  9. (甲)1001 A+B Format (20 分)

    题目: Calculate a+b and output the sum in standard format -- that is, the digits must be separated int ...

  10. 【PAT】1001. A+B Format

    http://pat.zju.edu.cn/contests/pat-a-practise/1001 此题花费了很长时间,做了几次都是说超时,网上找了个答案找到毛病,while(true)是绝对不能用 ...

最新文章

  1. HDU 3534 Tree (经典树形dp)
  2. 2021泰州高考什么时候查成绩查询,2021年泰州学院高考录取结果什么时候出来及查询系统入口...
  3. python网络编程--UDP客户端
  4. 多核分布式队列的实现:“偷”与“自私”的运用(1)
  5. 04737 c++ 自学考试2019版 第四章课后练习 程序设计题 2
  6. 即时系统和非即时系统的区别?_企业即时通讯系统拥有哪些二次开发能力?
  7. JAVA中的枚举使用总结
  8. ajax异步延迟加载图片,lazyload.JS实现图片异步延迟加载
  9. struts2拦截器实现登录拦截
  10. js 视频库 Video.js
  11. 电脑怎么修改照片尺寸?图片改大小如何改?
  12. 卡饭论坛--金山毒霸/卫士 广告过滤规则(附纯文本版) [2015.7.1] 党生日版
  13. Android工程师级别
  14. 不用再找懒人包了 | Windows安装苹果系统(dmg)原版
  15. 2k2实用球员_NBA2K Online2实用平民球员推荐:上篇
  16. 用Python在喜马拉雅音乐爬虫小试
  17. Photoshop脚本 锁定图层组所有图层
  18. 微型计算机的 I3 I5是,i3和i5性能差多少?i3和i5处理器的区别 (全文)
  19. Chrome之连接到网络 您正在使用的网络可能会要求您访问其登录页面解决方案
  20. 奢潮自信即刻拥有,KOREANO ESSENTIAL春夏系列上市

热门文章

  1. 计算机网络 —— OSI参考模型
  2. leetcode - 56. 合并区间
  3. leetcode - 813. 最大平均值和的分组
  4. 基于多源文档片段的神经网络排序模型(Neural Ranking Models with Multiple Document Fields)
  5. one-hot与词袋模型
  6. Spring线程池开发实战
  7. 各种搜索算法比较--2015年7月26日16:42:45V1.0版
  8. 计算机密码学奖,上海交通大学计算机科学与工程系(CSE)
  9. matlab 贝叶斯工具箱,matlab的BNT贝叶斯工具箱错误求教
  10. 没有第三个变量的前提下交换两个变量_JavaScript 交换值的方法,你能想到几种?