drkcore

2008/05/26 19:58:14

SRM171-DIV2-250

"3d18"みたいな文字列を二つのintに分けるのにfindとsubstrを使ったが、

string dice = "3d18";
int j = dice.find("d");
int rolls = atoi(dice.substr(0,j).c_str());
int num = atoi(dice.substr(j+1,dice.length() - j - 1).c_str());

そういう場合にはsscanfでよいらしい。

string dice = "3d18";
int n,s;
sscanf( dice.c_str(), "%dd%d",&n,&s);

それにしてもsplitがないのが不便だな。

Comments