又到了新一年的带团季了,今年准备用电脑来存放各种资料,自然也是需要一个简单的骰子工具了,反正也不复杂,就自己写了个,放着做个备份吧
主要功能是计算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;
}