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

你可能感兴趣的文章
MySQL 误操作后数据恢复(update,delete忘加where条件)
查看>>
MySQL 调优/优化的 101 个建议!
查看>>
mysql 转义字符用法_MySql 转义字符的使用说明
查看>>
mysql 输入密码秒退
查看>>
mysql 递归查找父节点_MySQL递归查询树状表的子节点、父节点具体实现
查看>>
mysql 通过查看mysql 配置参数、状态来优化你的mysql
查看>>
mysql 里对root及普通用户赋权及更改密码的一些命令
查看>>
Mysql 重置自增列的开始序号
查看>>
mysql 锁机制 mvcc_Mysql性能优化-事务、锁和MVCC
查看>>
MySQL 错误
查看>>
mysql 随机数 rand使用
查看>>
MySQL 面试题汇总
查看>>
MySQL 面试,必须掌握的 8 大核心点
查看>>
MySQL 高可用性之keepalived+mysql双主
查看>>
MySQL 高性能优化规范建议
查看>>
mysql 默认事务隔离级别下锁分析
查看>>
Mysql--逻辑架构
查看>>
MySql-2019-4-21-复习
查看>>
mysql-5.6.17-win32免安装版配置
查看>>
mysql-5.7.18安装
查看>>