首页 > 奇安信笔试(迷)

奇安信笔试(迷)

1.蒙的AC
class Solution {
public:
    /**
     * 
     * @param num_money int整型 奖金的总数,单位为元
     * @return int整型
     */
    int CalulateMethodCount(int num_money) {
        // write code here
        vector<int>dp(num_money+1,0);
        if(num_money==1)
            return 1;
        else if(num_money==2)
        {
            return 2;
        }
        else if(num_money==3)
            return 4;
        else 
        {
            dp[1]=1;
            dp[2]=2;
            dp[3]=4;
            for(int i=4;i<=num_money;i++)
                dp[i]=(dp[i-1]+dp[i-2]+dp[i-3]);
            return dp[num_money];
        }
    }
};
2.模拟
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s = "";
    while (getline(cin, s))
    {
        if (s.size() == 0)
        {
            cout << "" << endl;
        }
        else
        {
            vector<string> v;
            vector<string> result;
            vector<string> chexiao;
            int i = 0;
            while (i < s.size())
            {
                string temp = "";
                while (i < s.size() && s[i] != ' ')
                {
                    temp.push_back(s[i]);
                    i++;
                }
                i++; //跳过空格
                v.push_back(temp);
            }
            // for(int i=0;i<v.size();i++)
            // {
            //     cout<<i<<"  "<<v[i]<<endl;
            // }
            // cout<<endl;
            // cout<<endl;
            for (int i = 0; i < v.size(); i++)
            {
                if (v[i] == "undo")
                {
                    if (result.size() != 0)
                    {
                        chexiao.push_back(result[result.size() - 1]);
                        result.pop_back();
                    }
                }
                else if (v[i] == "redo")
                {
                    if (chexiao.size() != 0)
                    {
                        result.push_back(chexiao[chexiao.size() - 1]);
                        chexiao.pop_back();
                    }
                }
                else
                {
                    result.push_back(v[i]);
                }
            }
            for (int i = 0; i < result.size(); i++)
                cout << result[i] << " ";
            cout << endl;
        }
    }
}




全部评论

(2) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

近期热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐