使用特别一点的递归解法:详细看代码
汽水瓶
http://www.nowcoder.com/questionTerminal/fe298c55694f4ed39e256170ff2c205f
#include <iostream> using namespace std; int huan(int ping){ if(ping == 1) return 0; else if(ping == 2 ){ return 1; }else{ return huan(2)+huan(ping - 2); } } int main(){ int ping=0; while(cin>>ping){ if (ping>1) cout<<huan(ping)<<endl; } return 0; }