又到了新一年的带团季了,今年准备用电脑来存放各种资料,自然也是需要一个简单的骰子工具了,反正也不复杂,就自己写了个,放着做个备份吧

主要功能是计算x1dy1+/-x2dy2+/-.....+/-const这种表达式

#include <iostream>
#include <string>
#include <sstream>
#include <queue>
#include <ctime>
using namespace std;
int main(){
srand(time(0));
string sourcestring;
stringstream s;
int x,y,xlast,total;
char c,sign;
queue<int> dicerecode;
while(cin>>sourcestring){
s.clear();
s.str(sourcestring);
total=0;
sign=0;
while(!s.eof()){
xlast=0;
s>>x;
if(!s.eof()&&s>>c&&(c=='d'||c=='D')){
s>>y;
for(int i=0;i<x;i++){
int tmp=rand()%y+1;
xlast+=tmp;
dicerecode.push(tmp);
}
if(sign=='-') total-=xlast;
else total+=xlast;
if(!s.eof()) s>>sign;
}
else{
xlast+=x;
if(sign=='-') total-=xlast;
else total+=xlast;
sign=c;
}
}
cout<<"result="<<total<<"\t";
cout<<"(";
while(!dicerecode.empty()){
cout<<dicerecode.front();
if(dicerecode.size()>1) cout<<',';
dicerecode.pop();
}
cout<<")\n";
}
return 0;
}

最新文章

  1. .NET基础拾遗(5)多线程开发基础
  2. RPM包管理命令rpm
  3. thinkphp添加后台的构思以及添加数据功能
  4. Ubuntu 14.10 下安装navicat
  5. 【剑指offer 面试题7】用两个栈实现队列
  6. Excel报表
  7. KDE子项目一览 good
  8. 《Windows驱动开发技术详解》之编程加载NT式驱动
  9. ubuntu apache2 ssl配置
  10. mysql时间戳与日期格式的相互转换
  11. “《编程珠玑》(第2版)第2章”:C题(查找变位词,排序)
  12. Kafka 术语
  13. 1-VScode格式化ESlint-方法(最全最好用方法!)
  14. 使用super调用父类的构造方法
  15. JDK 规范目录
  16. 函数和常用模块【day06】:time模块 (一)
  17. 记录Java中对url中的参数进行编码
  18. session和cookie的异同
  19. Monkey Tradition---LightOj1319(中国剩余定理模板)
  20. CentOS 新系统后配置

热门文章

  1. Java 中怎么获取一份线程 dump 文件?
  2. memcached 的内存分配器是如何工作的?为什么不适用 malloc/free!?为何要使用 slabs?
  3. 什么是 Spring Framework?
  4. 1.0缓存:Login.aspx?
  5. 爬虫-数据解析-xpath
  6. MySQL优化篇(一),我可以和面试官多聊几句吗?——SQL优化流程与优化数据库对象
  7. C/C++头文件以及避免头文件包含造成的重定义方法
  8. 12_非线性理论基础_Lyapunov直接方法
  9. 一个很好用的 vue-picker组件
  10. 一块小饼干(Cookie)的故事-上篇