【求助】zoj 2476求和水题
2014-05-25 15:23
225 查看
据说是个水题,不过还是总WA。。求大神给瞄一眼。
题目描述如下:
Total Amount
Time Limit: 2 Seconds Memory Limit: 65536 KB
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
问题代码如下:
// ZOJ 2476.cpp : 定义控制台应用程序的入口点。
//
#include <iostream>
using namespace std;
int main()
{
int n,totalLeft,totalRight,dotLeft,dotRight;
char ch;
while(cin>>n&&n!=0)
{
totalLeft=0;
totalRight=0;
for(;n>0;n--)
{
cin>>ch;
int sum=0;
while(ch!='.')
{
cin>>dotLeft;
sum+=dotLeft;
cin>>ch;
if(ch==',')sum*=1000;
}
totalLeft+=sum;
cin>>dotRight;
totalRight+=dotRight;
}
totalLeft+=totalRight/100;
cout<<"$";
int baseNum=10000000,numOfZero=7,flag=0;
while(numOfZero)
{
if(flag==0&&totalLeft/baseNum)
{
cout<<totalLeft/baseNum;
flag=1;
}
else if(flag){
if((numOfZero+1)%3==0)cout<<',';
cout<<totalLeft/baseNum;
}
totalLeft%=baseNum;
baseNum/=10;
numOfZero--;
}
cout<<totalLeft<<'.';
totalRight%=100;
if(totalRight==0)cout<<"00"<<endl;
else cout<<totalRight<<endl;
}
//int sum=0;
return 0;
}
题目描述如下:
Total Amount
Time Limit: 2 Seconds Memory Limit: 65536 KB
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
问题代码如下:
// ZOJ 2476.cpp : 定义控制台应用程序的入口点。
//
#include <iostream>
using namespace std;
int main()
{
int n,totalLeft,totalRight,dotLeft,dotRight;
char ch;
while(cin>>n&&n!=0)
{
totalLeft=0;
totalRight=0;
for(;n>0;n--)
{
cin>>ch;
int sum=0;
while(ch!='.')
{
cin>>dotLeft;
sum+=dotLeft;
cin>>ch;
if(ch==',')sum*=1000;
}
totalLeft+=sum;
cin>>dotRight;
totalRight+=dotRight;
}
totalLeft+=totalRight/100;
cout<<"$";
int baseNum=10000000,numOfZero=7,flag=0;
while(numOfZero)
{
if(flag==0&&totalLeft/baseNum)
{
cout<<totalLeft/baseNum;
flag=1;
}
else if(flag){
if((numOfZero+1)%3==0)cout<<',';
cout<<totalLeft/baseNum;
}
totalLeft%=baseNum;
baseNum/=10;
numOfZero--;
}
cout<<totalLeft<<'.';
totalRight%=100;
if(totalRight==0)cout<<"00"<<endl;
else cout<<totalRight<<endl;
}
//int sum=0;
return 0;
}
相关文章推荐
- [ACM] ZOJ 3819 Average Score (水题)
- ZOJ 3705 3706 3708 3710 3712 3713 3714(水题)
- HDU1046 POJ1450 UVALive2334 ZOJ1037 Gridland【数学计算+水题】
- UVALive2363 POJ1005 HDU1065 ZOJ1049 I Think I Need a Houseboat【数学计算+水题】
- ZOJ - 2421 Recaman's Sequence(打表水题)
- ZOJ 3827 Information Entropy【水题、简单相加】
- POJ 2260(ZOJ 1949) Error Correction 一个水题
- UVALive2536 POJ1248 HDU1015 ZOJ1403 Safecracker【密码+暴力+水题】
- zoj 1874 水题,输出格式大坑
- zzulioj--1827--石锅全拌(区间求和水题)
- NYOJ【22】素数求和问题【水题】
- zoj1109 水题(大神绕道) Language of FatMouse
- 【水题】ZOJ 1048 Financial Management
- zoj 3809 The Himalayas 水题 The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- zoj2100Seeding(水题)
- zoj 2443 水题。。。
- ZOJ 2011 多项式求和
- zoj 2807Electrical Outlets 水题
- ZOJ 2476 Total Amount
- ZOJ水题分类