码迷,mamicode.com
首页 > 其他好文 > 详细

记一次失败的笔试(华为研发工程师-汽水瓶笔试题)

时间:2019-08-27 21:00:07      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:stream   ttl   col   研发   做事   ++   oid   namespace   lag   

#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);
    }
}

##做事不过脑子,还是太菜了!!!

 

记一次失败的笔试(华为研发工程师-汽水瓶笔试题)

标签:stream   ttl   col   研发   做事   ++   oid   namespace   lag   

原文地址:https://www.cnblogs.com/wasua/p/11420571.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!