Q
来源:互联网 发布:沙钢研究院待遇知乎 编辑:程序博客网 时间:2024/06/09 17:11
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
就是求出相加之和
分析:
先用字符串输入,然后转化成int类型进行加减
代码:
#include<bits/stdc++.h>using namespace std;int main(){ int n,v[100],w[100],longs,t,i,j,m,x; string a; while(cin>>n&&n) { memset(v,0,sizeof(v)); memset(w,0,sizeof(w)); longs=0; for(i=0;i<n;i++) { cin>>a; t=a.size(); for(j=t-1,m=1;j>=0;j--) if(a[j]>='0'&&a[j]<='9'){ v[m]=a[j]-'0'; m++; } longs=max(longs,m); for(j=1,x=0;j<longs;j++){ w[j]+=x+v[j]; x=w[j]/10; w[j]=w[j]%10; v[j]=0; } if(x>0){ w[j]=x; longs++; } } cout<<"$"; for(i=longs-1;i>0;i--){ if(i%3==2&&i!=2&&i!=longs-1) cout<<","; if(i==2) cout<<"."; cout<<w[i]; } cout<<endl; }}
感受:
就是麻烦,麻烦
- q
- q
- q
- Q
- q
- q
- q
- q
- Q
- q
- Q
- Q
- Q
- Q
- Q
- Q
- Q
- Q
- JavaScricpt —— 字符串之正则表达式演示
- Android问题—反编译APK获取代码&资源
- 实体字符
- 51nod没过的那题
- CPU核心数目 与 多线程
- Q
- Android打造自己的网络框架----RxJava的基础学习使用
- 第九章 内存模型和名称空间
- Qt实现截屏
- Evaluate Division
- SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID
- 面试
- 10w定时任务,如何高效触发超时(58沈剑)
- 荣耀Magic人工智能手机发布,买不到不如选择荣耀8