zoukankan      html  css  js  c++  java
  • 简单的TRPG骰子

    又到了新一年的带团季了,今年准备用电脑来存放各种资料,自然也是需要一个简单的骰子工具了,反正也不复杂,就自己写了个,放着做个备份吧
    主要功能是计算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<<"	";
            cout<<"(";
            while(!dicerecode.empty()){
                cout<<dicerecode.front();
                if(dicerecode.size()>1) cout<<',';
                dicerecode.pop();
            }
            cout<<")
    ";
        }
        return 0;
    }
    
  • 相关阅读:
    antd Icon
    antd button
    tree 向上查找(更新删除后页面的数据)
    tree 向下查找 (删除整条tree)
    tree结构统一修改属性名(递归)
    json转换为tree对象(递归)
    python测试题
    c函数练习
    飞机一只
    python1119作业1
  • 原文地址:https://www.cnblogs.com/kangyupl/p/13525251.html
Copyright © 2011-2022 走看看