#include<iostream> #include<fstream> using namespace std; int comp(int buttle, int current, int &drink); int main(void) { int n[10] = { 0,0,0,0,0,0,0,0,0,0 }; int N,i=0; ifstream infile("test.txt", ios::in); while (infile >> N) n[i++] = N; for (int j = 0; n[j] != 0; j++) { int buttle = n[j]; int drink = 0; int flag = comp(buttle, 0, drink); if (flag == 1) { int i = drink; drink = i + 1; } cout << drink << endl; } return 0; system("pause"); } int comp(int buttle, int current, int &drink) { current += buttle / 3; drink += current; buttle = buttle % 3+current; if (buttle < 2) return 0; else if (buttle == 2) { return 1; } else { current = 0; return comp(buttle, current, drink); } } ##做事不过脑子,还是太菜了!!!
原文地址:https://www.cnblogs.com/wasua/p/11420571.html
时间: 2024-10-07 22:30:05