博客
关于我
算法C++ 背包类似集合数据类型处理 弹珠处理(第一章)
阅读量:216 次
发布时间:2019-02-28

本文共 882 字,大约阅读时间需要 2 分钟。

造轮子博客链接

代码实现

```cpp #include
#include
#include
#include
using namespace std;

int main() {

int temp, numbers;
string colours[] = { "red", "blue", "green", "black", "pink", "yellow", "grey" };
set
s_marbles;
vector
marbles;

cout << "red-0 blue-1 green-2 black-3 pink-4 yellow-5 grey-6 else colours-else numbers" << endl;  cout << "input your marbles bags: -1 stop input" << endl;  while (cin >> temp) {      if (temp == -1) break;      marbles.push_back(temp);      s_marbles.insert(temp);  }  numbers = marbles.size();  for (const auto& tmp : s_marbles) {      if (tmp >= 0 && tmp < 7) {          int tempnumbers = count(marbles.begin(), marbles.end(), tmp);          cout << colours[tmp] << ":" << tempnumbers << endl;      } else {          cout << "others" << ":" << numbers << endl;      }  }

}

实现效果

通过上述代码,我们可以实现对弹珠背包的分类统计功能。用户可以通过输入数字来表示不同颜色的弹珠数量,系统会自动计算每种颜色弹珠的数量,并以指定格式输出结果。

转载地址:http://lfni.baihongyu.com/

你可能感兴趣的文章
Pandas中文官档~基础用法2
查看>>
SpringBoot+Vue+OpenOffice实现文档管理(文档上传、下载、在线预览)
查看>>
Pandas中文官档~基础用法5
查看>>
Pandas中文官档~基础用法6
查看>>
Pandas中的GROUP BY AND SUM不丢失列
查看>>
Pandas中的GROUP BY AND SUM不丢失列
查看>>
Pandas之iloc、loc
查看>>
pandas交换两列
查看>>
pandas介绍-ChatGPT4o作答
查看>>
pandas删除指定列里面内容的行
查看>>
pandas去除Nan值
查看>>
vc++多线程编程
查看>>
pandas实战:电商平台用户分析
查看>>
Pandas库函数
查看>>
Pandas库常用方法、函数集合
查看>>
Pandas循环提速 7 万多倍是怎么实现的?
查看>>
pandas打乱数据的顺序
查看>>
pandas指定列数据归一化
查看>>
pandas改变一列值(通过apply)
查看>>
Pandas数据分析的环境准备
查看>>