工大后院

 找回密码
 加入后院

扫一扫,访问微社区

QQ登录

只需一步,快速开始

搜索
查看: 1399|回复: 6

我得出答案系统还说我错,什么回事?

[复制链接]
发表于 2007-3-12 13:06 | 显示全部楼层 |阅读模式
这是我在北大OJ里的一道题目
我用我的代码能得出真确的答案
系统却说我错,怎么回事?
题目:
Description
Larry graduated this year and finally has a job. He's making a lot of money, but somehow never seems to have enough. Larry has decided that he needs to grab hold of his financial portfolio and solve his financing problems. The first step is to figure out what's been going on with his money. Larry has his bank account statements and wants to see how much money he has. Help Larry by writing a program to take his closing balance from each of the past twelve months and calculate his average account balance.
Input
The input will be twelve lines. Each line will contain the closing balance of his bank account for a particular month. Each number will be positive and displayed to the penny. No dollar sign will be included.
Output
The output will be a single number, the average (mean) of the closing balances for the twelve months. It will be rounded to the nearest penny, preceded immediately by a dollar sign, and followed by the end-of-line. There will be no other spaces or characters in the output.
Sample Input
100.00
489.12
12454.12
1234.10
823.05
109.20
5.27
1542.25
839.18
83.99
1295.01
1.75
Sample Output
$1581.42

代码
#include<stdio.h>
void main()
{
float cbm[12];
int i;
float sum=0;
float ave;
float *p=cbm;
for(i=1;i<=12;i++)
{
  scanf("%f",p);
  p++;
}
p=cbm;
for(i=1;i<=12;i++)
{
  sum+=*p;
  p++;
}
ave=sum/12;
printf("%6.2f",ave);
}

补上链接http://acm.pku.edu.cn/JudgeOnline/problem?id=1004

[ 本帖最后由 Ja5oN 于 2007-3-12 13:48 编辑 ]
发表于 2007-3-12 13:35 | 显示全部楼层
是格式问题吧..
回复

使用道具 举报

发表于 2007-3-12 13:36 | 显示全部楼层
建议下次最好把题目链接也帖出来
回复

使用道具 举报

发表于 2007-3-12 13:37 | 显示全部楼层
输出格式不对吧,多一个少一个字符都不行.
$号呢,
还有系统给的测试用例数值可能很大
回复

使用道具 举报

发表于 2007-3-12 13:41 | 显示全部楼层
#include<stdio.h>
int main()
{
float a=0,b;
int i=0;
while(i++<12){
   scanf("%f",&b);
   a+=b/12;
}
printf("$%6.2f",a);
return 0;
}
回复

使用道具 举报

 楼主| 发表于 2007-3-12 13:45 | 显示全部楼层
忘了“$”,又犯这种错误
不好意思
回复

使用道具 举报

发表于 2007-3-12 21:13 | 显示全部楼层
topCoder 上的题目

Problem Statement
&nbsp;&nbsp;&nbsp;&nbsp;
A Fountain of Life is a special fountain that produces the elixir of life at a constant speed of elixir liters per second. A dark mage managed to cast a Curse of Death on the Fountain so in addition to the elixir it now produces a deadly poison at a constant speed of poison liters per second. Both the poison and elixir are collected in an infinitely large pool around the Fountain and form a mixture. The mixture will become deadly once the percentage of poison in the mixture is at least 50%. Your task is to calculate the time at which the mixture will become deadly. At the beginning (0-th second) the pool contains pool liters of 100% elixir.  Your program must return a double, the time in seconds at which the mixture becomes deadly. If the mixture never becomes deadly, return -1.0.
Definition
&nbsp;&nbsp;&nbsp;&nbsp;
Class:
FountainOfLife
Method:
elixirOfDeath
Parameters:
int, int, int
Returns:
double
Method signature:
double elixirOfDeath(int elixir, int poison, int pool)
(be sure your method is public)
&nbsp;&nbsp;&nbsp;&nbsp;

Notes
-
The returned value must be accurate to within a relative or absolute value of 1E-9.
Constraints
-
elixir will be between 1 and 10000, inclusive.
-
poison will be between 1 and 10000, inclusive.
-
pool will be between 1 and 10000, inclusive.
Examples
0)

&nbsp;&nbsp;&nbsp;&nbsp;
1
2
2
Returns: 2.0
At t = 0s there are 2 liters of 100% elixir. At t = 1s there are 3 liters of elixir and 2 liters of poison for a total volume of 5 liters. 2 liters of poison is 40% of 5 liters so the mixture is still not deadly. At t = 2s there are 4 liters of elixir and 4 liters of poison for a total volume of 8 liters. 4 liters of poison is exactly 50% of the mixture so it is now deadly.
1)

&nbsp;&nbsp;&nbsp;&nbsp;
200
100
1
Returns: -1.0
With 200 liters of elixir per second and only 100 liters of poison per second, the mixture never becomes deadly.
2)

&nbsp;&nbsp;&nbsp;&nbsp;
9999
10000
10000
Returns: 10000.0
It might take a long time for the mixture to become deadly.
3)

&nbsp;&nbsp;&nbsp;&nbsp;
1
10000
1
Returns: 1.0001000100010001E-4
On the other hand, it might take a short time for the mixture to become deadly.
4)

&nbsp;&nbsp;&nbsp;&nbsp;
40
43
41
Returns: 13.666666666666666

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入后院

本版积分规则

QQ|Archiver|手机版|小黑屋|广告业务Q|工大后院 ( 粤ICP备10013660号 )

GMT+8, 2025-5-15 19:25

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表