re: Google面试题之补充 哈胖头 2007-08-16 14:17
Show一下我的程序:

int count_ones(int n)
{
static int pow10[]={1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};

int ones=0;

for(int m=n, b=0; m; m/=10, b++)
{
int d=m%10;
ones+=d*pow10[b]*b/10;
if(d>1) ones+=pow10[b];
if(d==1) ones+=n%pow10[b];
}

return ones;
}
re: 经典算法(7)--图的着色 哈胖头 2007-06-28 16:07
不错,图文并茂!
一行代码就足够了。不过不提倡这种方法。

string s;

copy(istreambuf_iterator<char>(ifstream("hello.txt").rdbuf()), istreambuf_iterator<char>(), back_inserter(s));
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿

随笔分类

搜索

最新评论