我在C++ 现在我被困在一个锻炼我,我不知道如何解决它C++练习煎饼
演习的目标是一个初学者:编写一个程序,要求用户输入号码由10个不同的人吃早餐和做一个列表从最高到最小像煎饼: 人6吃:10个煎饼 人吃了1:6个煎饼 等等
我有这样的代码:
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int person_num = 0;
int pancakes;
vector<int> pancake_list;
while (true) {
person_num = person_num + 1;
cout << "Please enter the number of pancakes eaten by Person #" << person_num << " ";
cin >> pancakes;
pancake_list.push_back(pancakes);
sort(begin(pancake_list), end(pancake_list));
reverse(begin(pancake_list), end(pancake_list));
if (person_num == 10) {
system("cls");
for (int i = 0; i < pancake_list.size(); i++) {
cout << pancake_list[i] << endl;
}
system("pause");
}
}
return 0;
}
的问题是,我不知道如何排序和扭转煎饼分配给正确的人 请帮助和解释
对不起,我的英语
你问过你的老师的帮助吗? – 2015-03-31 13:13:39
您可以使用地图来存储一个值(人数)的值(煎饼数量)。 http://www.cplusplus.com/reference/map/map/ – 2015-03-31 13:15:25
这不是来自学校,我正在学习C++,因为我真的很喜欢编程和这个练习是从网站 – 2015-03-31 13:15:34