VC++ 遇到一个棘手的问题 请教

来源:百度知道 编辑:UC知道 时间:2024/05/18 03:40:42
题目:现有巨大,大,中,小4种规格的容器,它们分别盛装50个,20个,5个,1个都佛尼。编写程序,读入要运输的都佛尼数目,求出每种规格的容器需要多少个,条件是容器数目和浪费的空间最小。请分别用3,18,48,78和10598作为输入量来运行程序。

这个题目百度知道上也有人提出来,不过参考了他的程序,我发现结果还是不对!! 请高手指点下!

我写的程序如下:

// Doforni.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "math.h"
#include <iostream>
#include <string>
using namespace std;

int main()
{
const int HUGE_DOFORNI=50;
const int BIG_DOFORNI=20;
const int MINDDLE_DOFORNI=5;
const int SMALL_DOFORNI=1;
int hugeNumber;
int bigNumber;
int middleNumber;
int smallNumber;
cout << "\nPlease enter the totle doforni number: ";
int totDoforniNum;
cin >> totDoforniNum;
hugeNumber = totDoforniNum/HUGE_DOFORNI;
bigNumber = totDoforniNum/HUGE_DOFORNI%BIG_DOFORNI;
middleNumber = (totDoforniNum/HUGE_DOFORNI%BIG_DOFORNI)%MINDDLE_DOFORNI;
smallNumber

代码修正后如下。
// Doforni.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "math.h"
#include <iostream>
#include <string>
using namespace std;

int main()
{
const int HUGE_DOFORNI=50;
const int BIG_DOFORNI=20;
const int MINDDLE_DOFORNI=5;
const int SMALL_DOFORNI=1;
int i;
int hugeNumber;
int bigNumber;
int middleNumber;
int smallNumber;
cout << "\nPlease enter the totle doforni number: ";
int totDoforniNum;
cin >> totDoforniNum;
hugeNumber = totDoforniNum/HUGE_DOFORNI;
bigNumber = totDoforniNum%HUGE_DOFORNI/BIG_DOFORNI; //从本行起连续3行错误,已经改正
middleNumber = (totDoforniNum%HUGE_DOFORNI%BIG_DOFORNI)/MINDDLE_DOFORNI;
smallNumber = ((totDoforniNum%HUGE_DOFORNI%BIG_DOFORNI)%MINDDLE_DOFORNI)/SMALL_DOFORNI;

cout << "\nThe huge doforni number is: " <<