博客
关于我
算法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 Connector/Net 句柄泄露
查看>>
multiprocessor(中)
查看>>
mysql CPU使用率过高的一次处理经历
查看>>
Multisim中555定时器使用技巧
查看>>
MySQL CRUD 数据表基础操作实战
查看>>
multisim变压器反馈式_穿过隔离栅供电:认识隔离式直流/ 直流偏置电源
查看>>
mysql csv import meets charset
查看>>
multivariate_normal TypeError: ufunc ‘add‘ output (typecode ‘O‘) could not be coerced to provided……
查看>>
MySQL DBA 数据库优化策略
查看>>
multi_index_container
查看>>
mutiplemap 总结
查看>>
MySQL Error Handling in Stored Procedures---转载
查看>>
MVC 区域功能
查看>>
MySQL FEDERATED 提示
查看>>
mysql generic安装_MySQL 5.6 Generic Binary安装与配置_MySQL
查看>>
Mysql group by
查看>>
MySQL I 有福啦,窗口函数大大提高了取数的效率!
查看>>
mysql id自动增长 初始值 Mysql重置auto_increment初始值
查看>>
MySQL in 太多过慢的 3 种解决方案
查看>>
Mysql Innodb 锁机制
查看>>