程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> VC >> vc教程 >> google競賽題SecretSum的C++解法

google競賽題SecretSum的C++解法

編輯:vc教程

SecretSum 是本次 google 競賽中第二輪淘汰賽的一道分值為 500 分競賽題。事實上,這道題目反而比同輪比賽中的那道 1000 分值的RecurringNumbers 難(RecurringNumbers 的難度水准充其量不過是道初一學生奧數競賽題)。好了,閒話少敘,來看 SecretSum 的題目吧:

一、競賽題目

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.

  1. 上一頁:
  2. 下一頁:
欄目導航
Copyright © 程式師世界 All Rights Reserved