SecretSum (code jam china round2 500分真题) (第二轮淘汰赛)

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值