Total Amount zoj 2476
2013-11-27 08:40
351 查看
Total Amount
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld
& %llu
Submit Status Practice ZOJ
2476
Description
Given a list of monetary amounts in a standard format, please calculate the total amount.
We define the format as follows:
1. The amount starts with '$'.
2. The amount could have a leading '0' if and only if it is less then 1.
3. The amount ends with a decimal point and exactly 2 following digits.
4. The digits to the left of the decimal point are separated into groups of three by commas (a group of one or two digits may appear on the left).
Input
The input consists of multiple tests. The first line of each test contains an integer N (1 <= N <= 10000) which indicates the number of amounts. The next N lines contain N amounts. All amounts and the total amount are between $0.00 and $20,000,000.00, inclusive.
N=0 denotes the end of input.
Output
For each input test, output the total amount.
Sample Input
2
$1,234,567.89
$9,876,543.21
3
$0.01
$0.10
$1.00
0
Sample Output
$11,111,111.10
$1.11
这个题目其实还是挺简单的,但是我就是死活都过不了,哎,还很水啊,
如果拿到省赛上这又是水题一道了,哎,这个题目其实还是很简单的,大数累加
再用一个string的字符串求出的数字字符串和逗号和小数点,然后逆序输出就是了,
就这么简单了。还有就是一些大数累加的知识,凭此程序以后可以搞定以后的大数
累加问题了,hehe
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld
& %llu
Submit Status Practice ZOJ
2476
Description
Given a list of monetary amounts in a standard format, please calculate the total amount.
We define the format as follows:
1. The amount starts with '$'.
2. The amount could have a leading '0' if and only if it is less then 1.
3. The amount ends with a decimal point and exactly 2 following digits.
4. The digits to the left of the decimal point are separated into groups of three by commas (a group of one or two digits may appear on the left).
Input
The input consists of multiple tests. The first line of each test contains an integer N (1 <= N <= 10000) which indicates the number of amounts. The next N lines contain N amounts. All amounts and the total amount are between $0.00 and $20,000,000.00, inclusive.
N=0 denotes the end of input.
Output
For each input test, output the total amount.
Sample Input
2
$1,234,567.89
$9,876,543.21
3
$0.01
$0.10
$1.00
0
Sample Output
$11,111,111.10
$1.11
这个题目其实还是挺简单的,但是我就是死活都过不了,哎,还很水啊,
如果拿到省赛上这又是水题一道了,哎,这个题目其实还是很简单的,大数累加
再用一个string的字符串求出的数字字符串和逗号和小数点,然后逆序输出就是了,
就这么简单了。还有就是一些大数累加的知识,凭此程序以后可以搞定以后的大数
累加问题了,hehe
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main() { int temp[100]; int ans[100]; char ten[100]; int i,j,n; while(scanf("%d",&n)!=EOF) { if(n==0) break; memset(ans,0,sizeof(ans)); int k=0; for(i=0; i<n; i++) { scanf("%s",ten); memset(temp,0,sizeof(temp)); int l=strlen(ten); k=0; for(j=0; j<l; j++) { if((ten[l-j-1]<='9')&&(ten[l-j-1]>='0')) { //printf("%cten",ten[j]); temp[k]=ten[l-j-1]-'0'; //printf("%d temp",temp[k]); k++; } } //for(i=0;i<k;i++) //printf("%dfdfd ",temp[i]); for(j=0; j<100; j++) { ans[j] = temp[j] + ans[j]; ans[j+1] += ans[j] / 10; ans[j] = ans[j] % 10; } } for(j=0; j<100; j++) if(ans[100-1-j]!=0) break; int la=100-1-j; //printf("%d%d\n",la,k); la=la>=k-1 ? la : k-1;//这个适用于0.00+0.00的那些情况,在那些情况下要用k的值,而非la了 // for(i=0; i<10; i++) // printf("%d",ans[j]); string a=""; // printf("%dla\n",la); for(j=0,i=1; j<=la; j++,i++) { a+= ans[j] + 48; //cout<<a<<endl; if(j==1) { a+= "."; i=0; } if(i%3==0&&i!=0&&i!=la-1) { a+= ","; } } a+= "$"; reverse(a.begin(), a.end());//字符串逆转 cout<<a<<endl; } return 0; }
相关文章推荐
- 数据库链接字符串查询网站
- Flex字符串比较 还有Flex字符串操作
- ASP下经常用的字符串等函数参考资料
- 将字符串小写转大写并延时输出的批处理代码
- 将字符串转换成System.Drawing.Color类型的方法
- 字符串聚合函数(去除重复值)
- Transformation 能将 Windows XP/Server 2003 操作系统,完美地模拟成 Windows Vista 的软件
- sqlserver中求字符串中汉字的个数的sql语句
- sql server字符串非空判断实现方法
- VBS的字符串及日期操作相关函数
- 用javascript和css模拟select的脚本
- C#中字符串编码处理
- MySQL 字符串函数大全
- php学习 字符串课件
- php5数字型字符串加解密代码
- 用MySQL函数清除字符串首尾空白字符的方法
- javascript用层模拟可移动的小窗口
- ASP为字符串中的网址自动加上链接
- vs2010根据字符串内容添加断点的方法介绍
- javascript String 对象