none
c++编程 RRS feed

答案

  • #include "stdafx.h"
    #include <iostream>
    using namespace std;
    #define MAX_VALUE	(5000)
    #define NUM_VALUE	(11)
    #define SUM_VALUE	(13)
    bool IsValidNumber(int nValue)
    {
    	int sum = 0;
    	while(nValue)
    	{
    		sum += (nValue % 10);
    		nValue /= 10;
    	}
    	return (sum == SUM_VALUE);
    }
    int main(int argc, char* argv[])
    {
    	for(int i = NUM_VALUE; i < MAX_VALUE; i += NUM_VALUE)
    	{
    		if(IsValidNumber(i))
    		{
    			cout<<i<<endl;
    		}
    	}
    	return 0;
    }
    期待有更好的算法。

    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.

    2012年9月6日 5:00
    版主

全部回复

  • #include "stdafx.h"
    #include <iostream>
    using namespace std;
    #define MAX_VALUE	(5000)
    #define NUM_VALUE	(11)
    #define SUM_VALUE	(13)
    bool IsValidNumber(int nValue)
    {
    	int sum = 0;
    	while(nValue)
    	{
    		sum += (nValue % 10);
    		nValue /= 10;
    	}
    	return (sum == SUM_VALUE);
    }
    int main(int argc, char* argv[])
    {
    	for(int i = NUM_VALUE; i < MAX_VALUE; i += NUM_VALUE)
    	{
    		if(IsValidNumber(i))
    		{
    			cout<<i<<endl;
    		}
    	}
    	return 0;
    }
    期待有更好的算法。

    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.

    2012年9月6日 5:00
    版主
  •   谢了。。。

    雷神

    2012年9月7日 4:28