記一次失敗的筆試(華爲研發工程師-汽水瓶筆試題)

#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); } }##作事不過腦子,仍是太菜了!!!
相關文章
相關標籤/搜索