思维会骗人,程序不骗人。


来自:http://blog.csdn.net/ndzjx/article


#include <iostream>

using namespace std;

int nCount = 10;
int nBegin = 5;
int nEnd = nBegin + nCount;
int narr[25] = { 1, 13, 3, 5, 8,
                 9, 2, 4, 13, 22,
                 44, 23, 7, 9, 0,
                 32, 13, 12, 6, 15,
                 14, 21, 16, 18, 4};
int main()
{
    // 我想把下面的for 改成上面的for,以为更简单了,
    // 其实不对(分析的数据源大了,得出的结果变多了)
    // 谨记:重构一定要写一个测试小程序!思维会骗人,程序不骗人。
    for (int i  = 0; i < 25; ++i)
    {
        int nValue = narr[i];
        if (nValue < nBegin || nValue >= nEnd)
        {
            cout << nValue << endl;
        }
    }


    for (int i = nBegin; i < nEnd; ++i)
    {
        bool bFlag = false;
        for (int j = 0; j < 25; ++j)
        {
            if (narr[j] == i)
            {
                bFlag = true;
                break;
            }
        }
        if (!bFlag)
        {
            cout << i << endl;
        }
    }
    return 0;
}



猜你喜欢

转载自blog.csdn.net/ndzjx/article/details/77882102
今日推荐