有道难题的初赛题2009年5月31

本文介绍了一种字符能量计算方法,参与者需要计算字符串中特定字符‘*’的能量总和。此外,还探讨了双倍超立方数的概念及其计数方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem Statement
????
在有道公司,每个月末都会为该月生日的员工举行集体的生日庆祝活动,每次活动都会做游戏。有一次的游戏是这样的,参加者会拿到一张有一段字符的纸条,字符只有(‘a’-‘z’), ‘+’, 还有‘*’。 ‘*’字符的能量是在它左侧的‘+’的个数。参加者需要在规定时间内计算出每个‘*’的能量,并且将这些能量相加,把结果告诉主持人。如果没有‘*’字符,则应该告诉主持人结果为0。如果回答正确,则可以获得奖品。
对于给定的字符串,返回所有’*’字符的能量和。
Definition
????
Class:
PowerString
Method:
power
Parameters:
string
Returns:
int
Method signature:
int power(string s)
(be sure your method is public)
????

Constraints
-
s 将包含1~50个字符
-
s 中只可能包括字符’*’, ‘+’, ‘a’-‘z’ (注意都是小写)
Examples
0)

????
"+**"
Returns: 2
对应*号的得分为1+1=2.
1)

????
"fd+*fd"
Returns: 1
对应*号的得分为1
2)

????
"*+*+*+*+*"
Returns: 10
对应*号的得分为 0+1+2+3+4=10.
3)

????
"+a*b+c+*d*+f*g"
Returns: 11

4)

????
"abcdefgh"
Returns: 0
没有*号.
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.


第二题


Problem Statement
????
双倍超立方数是指一个正整数可以正好被拆分为两种不同的a^3+b^3的方式,其中a,b均为整数且0<a<=b。对于任何一个指定的 int n, 返回所有的小于等于n的双倍超立方数的个数。
Definition
????
Class:
TwiceSuperCubic
Method:
count
Parameters:
int
Returns:
int
Method signature:
int count(int n)
(be sure your method is public)
????

Constraints
-
n取值范围为1到1,000,000,000(含)
Examples
0)

????
1
Returns: 0

1)

????
1729
Returns: 1
1729=1^3+12^3 1729=9^3+10^3
2)

????
475574
Returns: 27

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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值