TopCoder算法竞赛题4:SRM 148 DIV 2, 250-point
来源:互联网 发布:天下3张凯枫捏脸数据 编辑:程序博客网 时间:2024/05/29 11:21
Problem Statement
Create a class DivisorDigits containing a method howMany which takes an int number and returns how many digits in number divide evenly into number 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: 2
661232 is divisible by 1 and 2 (doubled).
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.
Sourece code
#include<iostream>
using namespace std;
class DivisorDigits
{
public:
int howMany(int number)
{
int count = 0;
int x = number;
while(x)
{
int y = x%10;
x/=10;
if(0 == y) continue;
if(0 == number%y) count++;
}
return count;
}
};
int main(void)
{
DivisorDigits dd;
// int cnt = dd.howMany(12345);
// int cnt = dd.howMany(730000000);
int cnt = dd.howMany(661232);
cout<<cnt<<endl;
return 0;
}
- TopCoder算法竞赛题4:SRM 148 DIV 2, 250-point
- TopCoder算法竞赛题2:SRM 146 DIV 2, 250-point
- TopCoder算法竞赛题1:SRM 144 DIV 2, 250-point
- TopCoder算法竞赛题3:SRM 147 DIV 2, 250-point
- TopCoder算法竞赛题5:SRM 149 DIV 2, 250-point
- TopCoder算法竞赛题6:SRM 150 DIV 2, 250-point
- 【topcoder SRM 702 DIV 2 250】TestTaking
- Topcoder SRM 462 DIV 2
- topcoder srm 518 div 2
- TopCoder SRM 561 Div 2
- Topcoder SRM 565 Div.2
- Topcoder SRM 628 DIV 2
- TopCoder SRM 144 DIV 2
- SRM 668 DIV 2 VerySecureEncryption 250point
- SRM 667 DIV 2 PointDistance 250-point
- SRM 669 DIV 2 LiveConcert 250-point
- SRM 670 DIV 2 Cdgame 250-point
- Topcoder SRM 709 DIV 2 250pt Robofactory solution
- MinGW Developer Studio 用上GCC 44了
- 浅谈Oracle数据库SCN号
- Net设计模式实例之代理模式(Proxy Pattern)
- TopCoder算法竞赛题2:SRM 146 DIV 2, 250-point
- TopCoder算法竞赛题3:SRM 147 DIV 2, 250-point
- TopCoder算法竞赛题4:SRM 148 DIV 2, 250-point
- Command模式
- 循序渐进实现仿QQ界面(四):圆形按钮与工具栏自绘
- 公务员、选调生考试申论万用句型 ,想考公务员的一定要看,最好打印并背诵•••(部分公务员待遇确实很诱惑人哦•••)
- net设计模式实例之组合模式(Composite Pattern)
- 桥接器模式
- 今夜我在看电影
- 基于Hemlock的ejabberd ActionScript游戏客户端开发
- 命令(Command)模式