1001. A+B Format

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 }
posted @ 2012-03-16 15:11  strorehouse  阅读(161)  评论(0编辑  收藏  举报