int main() { printSum("1abc23"); printSum("1abc2x30yz67"); }
int getStepNum(int n, int m) { int sumStep = 0; // 总台阶数为0时,终止递归循环 if (n == 0) { printSum(); return 1; } if (n >= m) { // 如果n大于每步最大台阶数,则设置第一步为m之内的一个台阶数,然后递归循环 int i = 1; while(i <= m) { step[len] = i; len++; sumStep += getStepNum(n - i, m); len--; i++; } } else { // 如果n小于m,则将一步最大台阶数缩小为n,重新递归 sumStep = getStepNum(n, n); } return sumStep; }
void IOQ::process(){ while(!ifAllFinish()){ //if there's new request can be added while(ifNewQeq()){ addNewReq(); } //if the running request finish, issue a new one if(ifRunningOneFinish()){ if(timer == 935) cout << ""; //get current track # if(running.getIndex() != -1){ track = running.getTrackNum(); //track has already move to this position finishedQ.push_back(running); } request req = getNextReq(); req.setIssueTime(timer); req.setFinishTime(timer + abs(track - req.getTrackNum())); running = req; if(running.getIndex() != -1 && running.getTrackNum() == track) timer--; } timer++; } printSum(); }