# zoj 2476 Total Amount

//这题主要是大数相加！不过要注意，有小数点！输出的格式也非常严格！WA了很多次，因为没有考虑到全是0.00相加的情况！
#include "iostream"
#include "string"
#include "memory.h"
#include "cctype"
#include "algorithm"
using namespace std;

int temp[20], ans[20];

int main()
{
int N, i, j, k, len, count;
string input, output;
while (cin >> N && N)
{
output = "";
memset(ans, 0, sizeof(ans));
for (i = 0; i < N; i++)
{
cin >> input;
memset(temp, 0, sizeof(temp));
len = input.length();
for (j = 0, count = 0; j < len; j++)//将字符转换为数字
{
if (isdigit(input[len-1-j]))
{
temp[count] = input[len-1-j] - 48;
count++;
}
}
for (j = 0; j < 20; j++)//大数相加的一般做法！
{
ans[j] = temp[j] + ans[j];
ans[j+1] += ans[j] / 10;
ans[j] = ans[j] % 10;
}

}
for (j = 0; j < 20; j++)
if (ans[20-1-j] != 0)
break;
k = 20-1-j;
k = k >= count-1 ? k : count-1;//判断是否忽略了前导0，这个需要特别留意，很容易出错！
for (j = 0, i = 1; j <= k; j++, i++)//格式的输出！
{
output += ans[j] + 48;
if (j == 1)
{
output += ".";
i = 0;
}
if (i%3 == 0 && i != 0 && i != k-1)
{
output += ",";
}
}
output += "$"; reverse(output.begin(), output.end()); cout << output << endl; } return 0; } /* 3$11,999,999.99
$99,999,999.99$111,999,999.11
3
$0.00$0.00
\$0.00
*/



#### ZOJ 2476 Total Amount

2014-02-25 11:22:52

#### Total Amount zoj 2476

2013-11-27 08:40:11

#### ZOJ 2476 Total Amount

2013-03-22 10:54:19

#### ZOJ 2476 Total Amount （字符串处理）

2015-02-06 22:08:59

#### zoj 2476 Total Amount（水~）

2011-01-22 09:51:00

#### ZOJ 2476 Total Amount 字符串

2014-01-03 23:45:09

#### ZOJ 2476 Total Amount A的好辛苦

2013-11-25 08:57:01

#### ZOJ Problem Set - 2476 Total Amount

2015-01-26 21:01:47

#### B-Total Amount (ZOJ 2476)

2014-03-31 15:38:39

#### zoj 2476 Total Amount(模拟题，细节处理特别多)

2013-11-28 20:14:04