# zoj2476

243人阅读 评论(0)

#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
ifstream cin("2467.txt");
string s1, s2, temp;
int flag, a, b, sum;
int n;
map<char, int> m1;
m1['0'] = 0;
m1['1'] = 1;
m1['2'] = 2;
m1['3'] = 3;
m1['4'] = 4;
m1['5'] = 5;
m1['6'] = 6;
m1['7'] = 7;
m1['8'] = 8;
m1['9'] = 9;
map<int, char> m2;
m2[0] = '0';
m2[1] = '1';
m2[2] = '2';
m2[3] = '3';
m2[4] = '4';
m2[5] = '5';
m2[6] = '6';
m2[7] = '7';
m2[8] = '8';
m2[9] = '9';
while (cin >> n && n)
{
for (int i = 0; i < n; ++i)
{
temp = "";
cin >> s2;
//删除$号 s2.erase(0, 1); //删除‘，’号 for (int j = 0; j < s2.size(); ++j) { if (s2[j] != ',') temp += s2[j]; } s2 = temp; //翻转 reverse(s2.begin(), s2.end()); //删除'.'号 s2.erase(2, 1); if (i == 0)s1 = s2; else { //s1 + s2 sum = flag = 0; if (s1.size() < s2.size()) { temp = s1; s1 = s2; s2 = temp; } for (int k = 0; k < s1.size(); ++k) { a = m1[s1[k]]; if (k >= s2.size())b = 0; else b = m1[s2[k]]; sum = a + b + flag; if (sum > 9) { sum = sum - 10; flag = 1; } else flag = 0; s1[k] = m2[sum]; } if (flag == 1)s1 += "1"; } } //加入小数点和逗号 temp = ""; for (int k = 0; k < s1.size(); ++k) { temp += s1[k]; if (k == 1)temp += "."; if ((k - 1) % 3 == 0 && k != 1 && k != (s1.size() - 1)) temp += ","; } s1 = temp; cout << "$";
for (int i = s1.size() - 1; i >= 0; --i)
cout << s1[i];
cout << endl;
}
return 0;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：12756次
• 积分：482
• 等级：
• 排名：千里之外
• 原创：37篇
• 转载：3篇
• 译文：0篇
• 评论：0条
文章分类
文章存档