TopCoder 250 points 10-SRM 148 DIV 2 167.20/250 66.88%

Problem Statement

 Create a class DivisorDigits containing a method howMany which takes an int number and returns how many digits in number divide evenly intonumber itself.

Definition

 
Class:DivisorDigits
Method:howMany
Parameters:int
Returns:int
Method signature:int howMany(int number)
(be sure your method is public)
 
 

Notes

-No number is divisible by 0.

Constraints

-number will be between 10000 and 999999999.

Examples

0) 
 
12345
Returns: 3
12345 is divisible by 1, 3, and 5.
1) 
 
661232
Returns: 3
661232 is divisible by 1 and 2.
2) 
 
52527
Returns: 0
52527 is not divisible by 5, 2, or 7.
3) 
 
730000000
Returns: 0
Nothing is divisible by 0. In this case, the number is also not divisible by 7 or 3.

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.     

public class DivisorDigits {


	public  int howMany(int number) {
		int copynum = number;
		int sum = 0;
		int digit;
		int num[] = new int[10];
		while (number > 0) {
			digit = number % 10;
			num[digit]++;
			number = number / 10;
		}
		for (int i = 1; i < 10; i++) {
			if (num[i] > 0)
				if (copynum % i == 0)
					sum += num[i];
		}

		return sum;

	}

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值