65,206
社区成员
发帖
与我相关
我的任务
分享int box_count = 1;
void get_candy(int box_level)
{
if (box_level == 0)
{
cout << "get a candy" << endl;
}
else
{
cout << "open box " << box_count++ << endl;
get_candy(box_level - 1);
cout << "close box " << box_count-- << endl;
}
}#include <iostream>
template <int n> void get_sugar(int x)
{
if (x>n)
return;
std::cout<<"open the "<<x<<"box\n";
if (x==n)
std::cout<<"get a sugar \n";
get_sugar<n>(x+1);
std::cout<<"close the "<<x<<"box\n";
}
template <int n> void bot_get()
{
get_sugar<n>(1);
}
int main()
{
bot_get<3>();
}