当前位置:七道奇文章资讯编程技术VC/C++编程
日期:2011-03-22 13:55:00  来源:本站整理

<b>谷歌比赛题SecretSum的C++解法</b>[VC/C++编程]

赞助商链接



  本文“<b>谷歌比赛题SecretSum的C++解法</b>[VC/C++编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:

SecretSum 是本次 谷歌 比赛中第二轮淘汰赛的一道分值为 500 分比赛题.事实上,这道标题反而比同轮比赛中的那道 1000 分值的RecurringNumbers 难(RecurringNumbers 的难度水准充其量不过是道初一学生奥数比赛题).好了,闲话少叙,来看 SecretSum 的标题吧:

1、比赛标题

Problem Statement

We can substitute each digit of a number with a unique letter from ''A'' to ''Z''. This way we can write groups of numbers in a single representation. For example "ABA" can represent any of the following: 101, 151, 343, 767, 929. However, "ABA" cannot mean 555 because each letter must stand for a distinct digit. Furthermore, numbers cannot begin with 0 and thus ''A'' cannot be replaced by 0. Given two such representations num1 and num2 and the result of their summation return the total number of possible combinations of numbers for which the equation holds. If no combinations are possible then return 0.

Definition

Class: SecretSum

Method: countPossible

Parameters: String, String, String

Returns: int

Method signature: int countPossible(String num1, String num2, String result)

(be sure your method is public)

Constraints

- num1, num2, and result will each contain exactly 3 uppercase letters (''A'' - ''Z'').

Examples

0)

"AAA"

"BBB"

"CCC"

Returns: 32

1)

"ABB"

"DEE"

"TTT"

Returns: 112

2)

"ABC"

"ABA"

"ACC"

Returns: 0

Leading zeroes are not allowed.

3)

"AAA"

"CDD"

"BAA"

Returns: 32

4)

"TEF"

"FET"

"AAA"

Returns: 12

5)

"ABC"

"ABC"

"BCE"

Returns: 5

We can have the following 5 sums:

124 + 124 = 248

125 + 125 = 250

249 + 249 = 498

374 + 374 = 748

375 + 375 = 750

6)

"AAA"

"AAA"

"BBB"

Returns: 4

We can have the following 4 sums:

111 + 111 = 222

222 + 222 = 444

333 + 333 = 666

444 + 444 = 888

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.

标题的意思大致是这样的:数字0-9可以辨别用A-Z中不相同的字母替换,这样便可以用字母构成的字符串代表一个数了.比方"ABA"可以代表: 101, 151, 343, 767, 929.但"ABA"不可以代表555,因为差别的字母必须取差别的数字.此外每个作为开首的字母不取0值.编写一个类 SecretSum,该类中有一个原型为 int countPossible(string num1, string num2, string result)的函数.num1、num2 和 result 就是上面所描写的范例的字符串,此中 result 代表的数为 num1 和 num2 代表的数的和,并且这几个字符串都只含有3个A-Z的字母.返回值为大概获得的组合的总数.
  以上是“<b>谷歌比赛题SecretSum的C++解法</b>[VC/C++编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:

  • <b>hosts是什么 hosts文件在什么位置 若何改正hosts</b>
  • <b>在 Windows 8 中手动安装语言包</b>
  • <b>五个常见 PHP数据库问题</b>
  • Windows中Alt键的12个高效快速的利用本领介绍
  • <b>MySQL ORDER BY 的实现解析</b>
  • <b>详解MySQL存储历程参数有三种范例(in、out、inout)</b>
  • <b>Win8系统恢复出来经典的开始菜单的办法</b>
  • <b>Win8系统花屏怎么办 Win8系统花屏的办理办法</b>
  • <b>Windows 7系统下无线网卡安装</b>
  • <b>为什么 Linux不需求碎片整理</b>
  • <b>Windows 8中删除账户的几种办法(图)</b>
  • <b>教你如安在win7下配置路由器</b>
  • 本文地址: 与您的QQ/BBS好友分享!
    • 好的评价 如果您觉得此文章好,就请您
        0%(0)
    • 差的评价 如果您觉得此文章差,就请您
        0%(0)

    文章评论评论内容只代表网友观点,与本站立场无关!

       评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
    Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .