zoukankan      html  css  js  c++  java
  • 记一次失败的笔试(华为研发工程师-汽水瓶笔试题)

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

    ##做事不过脑子,还是太菜了!!!
  • 相关阅读:
    三、linux系统管理
    二、基本命令
    一、基本环境
    mysql-day4
    mysql-day3
    mysql-day2
    mysql-day1
    3、线性表的链式存储结构
    2、线性表之顺序表
    1、时间复杂度
  • 原文地址:https://www.cnblogs.com/wasua/p/11420571.html
Copyright © 2011-2022 走看看