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

你可能感兴趣的文章
MYSQL8.0以上忘记root密码
查看>>
Mysql8.0以上重置初始密码的方法
查看>>
mysql8.0新特性-自增变量的持久化
查看>>
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8修改密码的方法
查看>>
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>
Mysql8在Windows上离线安装时忘记root密码
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>
mysql8的安装与卸载
查看>>
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>
Mysql: 对换(替换)两条记录的同一个字段值
查看>>
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>
MYSQL:基础——触发器
查看>>
Mysql:连接报错“closing inbound before receiving peer‘s close_notify”
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>
mysqldump 参数--lock-tables浅析
查看>>