20220303蔚来笔试

1

#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

const int N = 110;
int num[N];
int v;

int main(){
    int t;
    int idx = 0;
    int mx = -1;
    while(cin >> t){
        num[idx++] = t;
        mx = t >= mx ? t : mx;
        if(cin.get() == '\n') break;
    }

    cin >> v;

//    cout <<"v:" << v << endl;
//    cout << "idx:" << idx << endl;

    string ans = "[";
    for(int i=0; i < idx; ++i)
    {
        if(num[i] + v >= mx){
            ans += "True, ";
        }else{
            ans += "False, ";
        }
    }

    ans.pop_back(); ans.pop_back();
    ans.push_back(']');
    cout << ans << endl;
}

3

#include <string>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 将输入的整数 n(0 <= n && n < 1千万)转换为中文数字大写格式
     * @param n int整型 输入的整数
     * @return string字符串
     1        1
     11       1s1
     111      1b1s1
     1111     1q1b1s1
     11111    1w1q1b1s1
     111111   s1w1q1b1s1
     1111111  1b1s1w1q1b1s1
     11111111 1q1b1s1w1q1b1s1
     10111111 1q01s1w1q1b1s1
     10011111 1q01w1q1b1s1
     11101111 1q1b1sw01q1b1s1
     从后往前走: 数 + 位
         如果超过四位,则加一个w
         如果得到0,则添加0
     删除连续0
     */
    char w[6] = {'n', 'n','s','b','q','w'};

    string chinese_number(int n) {
        string ans = "";
        int idx = 0;
        while (n) {
            int t = n % 10;
            n /= 10;
            idx++;
            if (idx > 4) {
                idx %= 4;
                ans.push_back('w');
            }
            if(idx != 1 && t != 0) ans.push_back(w[idx]);
            ans.push_back('0' + t);
        }

        if(ans.size() >= 2 && ans[ans.size()-1] == '1' && ans[ans.size()-2] == 's') ans.pop_back();
        reverse(ans.begin(), ans.end());

        string res = "";
        int l=0, r=0;
        bool isZero = false;
        for(int i=0; i<ans.size(); i++){
            if(ans[i] != '0'){
                res.push_back(ans[i]);
                isZero = false;
            }
            else{
                if(isZero == true){
                    continue;
                }else{
                    res.push_back(ans[i]);
                    isZero = true;
                }
            }
        }

        ans.clear();
        for(int i=0; i<res.size(); i++){
            if(res[i] == '0' && i+1 < res.size() && res[i+1] == 'w') continue;
            else ans.push_back(res[i]);
        }

        while(ans.back() == '0') ans.pop_back();

        return ans;
    }
};

int main(){
    Solution sol;
    vector<pair<int, string>> vic = {
            { 11, "s1" },
            { 302, "3b02" },
            { 57049, "5w7q04s9" },
            { 600080, "6sw08s" },
            { 32000523, "3q2bw05b2s3" },
            { 12345678, "1q2b3s4w5q6b7s8" }
    };

    for(auto& p:vic){
        string ans = sol.chinese_number(p.first);
        cout << p.first << "  " << p.second << ":" << ans << " isright:" << (ans == p.second) << endl;
    }


}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ColaForced

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值