2008年8月31日 星期日

[计划]08年9月1日到08年12月31日计划


我要转程序,这是应当严肃面对的事情,
我的缺陷主要是 写的代码少(准确说是写的大工程的代码少)
为了弥补这个缺陷,决定和biubiu完成一个简单的2D网游设计
1、完成客户端的设计,首先是消息处理;
2、用OpenGL实现2D引擎
3、完成游戏逻辑的设计
4、形成一个单机游戏
5、写服务器端
 
要补习的书
1、windows程序设计
2、编程精粹
3、编程珠玑
4、Linux的一些程序开发
5、图形学相关知识
6、数学相关知识
 
一定要多写代码,即使在这个公司转不了程序,也可以去其它公司!
--
Copyright(c) Beingstudio
Author:Chenshicai
Email or MSN or Gtalk:beingstudio@gmail.com
Blog:http://beingstudio.blogspot.com/

2008年8月22日 星期五

[C++]1的数目 解答

给定一个十进制正整数N,写下从1开始,到N的所有整数,然后数一下其中出现的所有"1"的个数。
例如:
N= 2,写下1,2。这样只出现了1个"1"。
N= 12,我们会写下1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12。这样,1的个数是5。
问题是:
写一个函数f(N),返回1到N之间出现的"1"的个数,比如f(12)=5。
题目所在网页 http://www.msra.cn/Articles/ArticleItem.aspx?Guid=8ae08db5-e059-44bf-9181-83d40a67dadb
 
我的做法是 分治,代码如下
int GetCount(int nNum)
{
    int nResult = 0;
    int nValue = nNum;
    int nPos = 0;
    int nCount = 1;
    int i = 0;
    int nTenPower = 1;
    int nTotalCount = 0;
    while (true)
    {
        nPos = nValue % 10;   
        nCount = nPos * nTotalCount;
        nResult += nCount;
       
       
        if (nPos == NUM)
        {
            nCount = nNum % nTenPower + 1;
            nResult += nCount;
        }
        if (nPos > NUM)
        {
            nCount = nTenPower;
            nResult += nCount;
        }
        nValue /= 10;
        if (!nValue)
            break;
        nTotalCount = nTenPower + nTotalCount * 10;
        nTenPower *= 10;
        i++;       
    }
    return nResult;
}

--
Copyright(c) Beingstudio  
Author:Chenshicai