博客
关于我
算法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/

你可能感兴趣的文章
MySQL5.6忘记root密码(win平台)
查看>>
MySQL5.6的Linux安装shell脚本之二进制安装(一)
查看>>
MySQL5.6的zip包安装教程
查看>>
mysql5.7 for windows_MySQL 5.7 for Windows 解压缩版配置安装
查看>>
Webpack 基本环境搭建
查看>>
mysql5.7 安装版 表不能输入汉字解决方案
查看>>
MySQL5.7.18主从复制搭建(一主一从)
查看>>
MySQL5.7.19-win64安装启动
查看>>
mysql5.7.19安装图解_mysql5.7.19 winx64解压缩版安装配置教程
查看>>
MySQL5.7.37windows解压版的安装使用
查看>>
mysql5.7免费下载地址
查看>>
mysql5.7命令总结
查看>>
mysql5.7安装
查看>>
mysql5.7性能调优my.ini
查看>>
MySQL5.7新增Performance Schema表
查看>>
Mysql5.7深入学习 1.MySQL 5.7 中的新增功能
查看>>
Webpack 之 basic chunk graph
查看>>
Mysql5.7版本单机版my.cnf配置文件
查看>>
mysql5.7的安装和Navicat的安装
查看>>
mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
查看>>