打印

[原创] 一道经典的C++题,关于分钱的问题,适合新手阅读

看看答案- -!好像又点难- -!

TOP

看看哈.......................................................................
只能说.........别说答案写错了,就从效率上讲用三个循环做也是
这种穷举法在去看书吧
作为程序员能自己做的就不要留给cpu去做!!!!!!

TOP

sgdfhfghg

茜素 23r2354saff asdgfgdfhh
先看看再说!!!

TOP

kan kan
学习中,虽然还不会,多看朋友们的大作!!!!!

TOP

学习中,虽然还不会,多看朋友们的大作!!!!!
// 一元换钢镚.cpp : Defines the entry point for the console application.
//======================================================================
#include "stdafx.h"
#include "iostream.h"
int sum=0;                                                //sum 每多一种分法,sum加1
int five=0;                                                //five 5分
int two=0;                                                //two  2分
int one=0;                        //one  1分
int main()
//----------------------------------------------------------------------
{
        for (five; five<=20; five++){
                for (two; two<=50; two++){
                        for(one; one<=100; one++){
                                if(one+two+five>19 && one+2*two+5*five==100){
                                                cout<<"one:"<<" "<<one<<","<<"two:"<<" "<<two<<","<<"five:"<<five<<endl;
                                                sum++;
                                }
                        }
                        one=0;
                }
                two=0;
        }
        cout <<sum <<endl;
        return 0;
}//======================================================================

TOP

kan kan.xue xi xia

Processed in 0.027068 second(s), 5 queries, Gzip enabled