牛客网——华为题库(21~30)


21.简单密码

//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <unordered_map>
#include <cstring>

using namespace std;

unordered_map<string, char> m = {
    {"1", '1'},
    {"abc", '2'},
    {"def", '3'},
    {"ghi", '4'},
    {"jkl", '5'},
    {"mno", '6'},
    {"pqrs", '7'},
    {"tuv", '8'},
    {"wxyz", '9'},
    {"0", '0'},
};


int main(){
    string str = "";
    cin>>str;

    string res = "";
    for(char c : str){
        char ch;
        if(!isdigit(c)){ //如果不是数字
            if(c >= 'a' && c <= 'z'){
                for(auto iter = m.begin(); iter != m.end(); iter++){  
                    //cout<<iter->first.c_str()<<endl;
                    //cout<<iter->second<<endl;
                    if(iter->first.find(c) != iter->first.npos){ //找到了
                        ch = iter->second;
                        //cout<<ch<<endl;
                        res += ch;
                        break;
                    }
                }              
            }
            
            else if(c >= 'A' && c <= 'Z'){
                if(c == 'Z'){ //特殊情况
                    ch = 'a';
                }
                else{
                    ch = c + 33; //先变成小写,再往后移一位
                }            
                res += ch;
            }
            
        }
        else{
            res += c;
        }
        
    }
    
    cout<<res<<endl;
    
    return 0;
}

22.汽水瓶

#include <iostream>
#include <vector>

using namespace std;

void process(int num, int& ans){
    if(num < 2) ans = 0;
    
    while(num >= 2){       
        ans += 1;
        num -= 3;
        num += 1;
    }  
}

int main(){
    int num = 0;
    vector<int> res;
    while(cin>>num && num != 0){
        int ans = 0;
        process(num, ans);
        res.push_back(ans);
    }
    
    for(int i = 0; i < res.size(); i++){
        cout<<res[i]<<endl;
    }
    
    return 0;
}

23.删除字符串中出现次数最少的字符

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

using namespace std;

int main(){
    string str = "";
    cin >> str;
    
    unordered_map<char, int> m;
    for(char c : str){
        m[c]++;
    }
    
    vector<int> tmp;
    for(auto iter = m.begin(); iter != m.end(); iter++){
        tmp.push_back(iter->second);
    }
    sort(tmp.begin(), tmp.end());
    
    string res = "";
    for(char c : str){
        if(m[c] != tmp[0]){
            res += c;
        }
    }
    
    cout << res << endl;
    
    return 0;
}

24.合唱队

#include <bits/stdc++.h>

using namespace std;

void process(vector<int> vec, int N, int& res){
    vector<int> leftNum(N, 0);
    vector<int> rightNum(N, 0);

    //左边的最长序列长度
    for(int i = 0; i < N; i++){
        for(int j = 0; j < i; j++){
            if(vec[j] < vec[i]){
                leftNum[i] = max(leftNum[i], leftNum[j]);
            }
        }
        leftNum[i] = leftNum[i] + 1;
        //cout << leftNum[i]<<endl;
    }
    
    //右边的最长序列长度
    for(int i = N - 1; i >= 0; i--){
        for(int j = N - 1; j > i; j--){
            if(vec[i] > vec[j]){
                rightNum[i] = max(rightNum[i], rightNum[j]);
            }
        }
        rightNum[i] = rightNum[i] + 1;
    }
    
    //求最长的序列长度
    int maxValue = INT_MIN;
    for(int i = 0; i < N; i++){
        maxValue = max(maxValue, leftNum[i] + rightNum[i] - 1); //
    }
    
    res = N - maxValue;
    
    return;
}

int main(){
    int N = 0;
    cin >> N;
    vector<int> vec;
    int h = 0;
    for(int i = 0; i < N; i++){  
        cin >> h;
        vec.push_back(h);
    }

    int res = 0;
    process(vec, N, res);
    cout << res << endl;
    
    return 0;
}

25.数据分类处理

#include <bits/stdc++.h>

using namespace std;

bool isExist(string strI, string s){
    return strstr(strI.c_str(), s.c_str()) != nullptr; //在strI中找s第一次出现的位置
}

void process(int sizeI, int sizeR, vector<int> I, vector<int> R){
    sort(R.begin(), R.end()); //排序
    //unique函数:”删除”序列中所有相邻的重复元素(只保留一个)。此处的删除,并不是真的删除,而是指重复元素的位置被不重复的元素给占领了
    //单纯的使用unique函数的话,容器的长度并没有发生变化,只是元素的位置发生了变化
    //返回值是一个迭代器,它指向的是去重后容器中不重复序列的最后一个元素的下一个元素。
    //如1334667——>1346767,指向第2个6的位置;
    //所以要搭配erase使用
    vector<int>::iterator new_end = unique(R.begin(), R.end());//去重 
    R.erase(new_end, R.end());

    unordered_map<string, vector<pair<string, int>>> mp;
    for(int i = 0; i < R.size(); i++){
        //cout << R[i] << " " << endl; //排序去重后的R   
        string tmp_rs = to_string(R[i]);  
        //cout << tmp_rs << endl;
        for(int j = 0; j < I.size(); j++){
            string tmp_is = to_string(I[j]);
            if(isExist(tmp_is, tmp_rs)){
                //cout << j << " ";
                mp[tmp_rs].push_back(make_pair(tmp_is, j));
            }                     
        }
    }

    vector<string> res;
    for(int i = 0; i < R.size(); i++){
        for(auto item = mp.begin(); item != mp.end(); item++){     
            if(item->first == to_string(R[i])){
                res.push_back(item->first);
                int baohanNum = item->second.size();
                res.push_back(to_string(baohanNum));
                for(int idx = 0; idx < baohanNum; idx++){
                    res.push_back(to_string(item->second[idx].second));
                    res.push_back(item->second[idx].first);
                }
            }          
        }     
    }
    
    cout << res.size() << " ";
    for(auto x : res){
        cout << x << " ";
    }
    cout << endl;       
}

int main(){
    int m = 0, n = 0;
    
    cin >> m;
    vector<int> I(m, 0); 
    for(int i = 0; i < m; i++){
        int num = 0;
        cin >> num;
        I[i] = num;
    }
    
    cin >> n;
    vector<int> R(n);   
    for(int i = 0; i < n; i++){
        int num = 0;
        cin >> num;
        R[i] = num;
    }
    
    process(m, n, I, R);
    
    return 0;
}

26.字符串排序

#include<bits/stdc++.h>

using namespace std;

int main(){
    string str = "";
    getline(cin, str);
    char out[1000];
    int k = 0;
    
    for(int i = 0; i <= 26; i++){ //
        for(int j = 0; j < str.size(); j++){
            if(str[j] - 'a' == i || str[j] - 'A' == i){ //
                out[k++] = str[j];//out中存放的便是按照顺序的字符串
            }
        }
    }
    //for(int i = 0; i < strlen(out); i++)
    //cout<<out[i];
    k = 0;
    for(int i = 0; i < str.size(); i++){
        if(isalpha(str[i])){
            str[i] = out[k++]; //
        }
    }
    
    cout<<str<<endl;
    return 0;
}

27.查找兄弟单词

#include <bits/stdc++.h>

using namespace std;

void process(int wordsNum, int& ans, string& res){
    vector<string> vecStr(wordsNum, "");
    for(int i = 0; i < wordsNum; i++){
        string s = "";
        cin >> s;
        vecStr[i] = s;
    }
    string word = "";
    cin >> word;
    int k = 0;
    cin >> k;
    
    unordered_map<string, vector<string>> m;
    string w = word;
    sort(w.begin(), w.end());
    for(int i = 0; i < vecStr.size(); i++){
        string tmp = vecStr[i];
        sort(tmp.begin(), tmp.end());
        if(tmp == w && vecStr[i] != word){
            m[word].push_back(vecStr[i]);
            
            //cout << vecStr[i]<<endl;
        }
    }
    sort(m[word].begin(), m[word].end());
    
    ans = m[word].size();
    if(k < ans){ //
        res = m[word][k - 1];
    }
    
    return;
}

int main(){
    int wordsNum = 0; 
    int ans = 0;
    string res = "";
    while(cin >> wordsNum){
        process(wordsNum, ans, res);
        
        cout << ans << endl;
        if(res != ""){ //
            cout << res << endl;
        }       
    }
    
    return 0;
}

28.素数伴侣

#include <bits/stdc++.h>

using namespace std;

//判断一个数是否是素数
bool isPrime(int num){
    for(int i = 2; i * i <= num; i++){
        if(num % i == 0){
            return false;
        }
    }
    
    return true;
}

bool find(int num, vector<int> evens, vector<bool>& used, vector<int>& match){
    for(int i = 0; i < evens.size(); i++){//遍历每个偶数与奇数比较
        if(isPrime(num + evens[i]) && !used[i]){
            used[i] = true;
            //如果第i个偶数还未配对,或者跟它配对的奇数还有别的选择
            if(match[i] == 0 || find(match[i], evens, used, match)){ 
                match[i] = num; //则配对该数
                return true;
            }
        }
    }
    
    return false;
}

int main(){
    int n = 0;
    cin >> n;
    vector<int> nums(n);
    vector<int> odds; //奇数数组
    vector<int> evens; //偶数数组
    
    for(int i = 0; i < n; i++){
        cin >> nums[i];
        if(nums[i] % 2 != 0) odds.push_back(nums[i]); //奇数数组
        else evens.push_back(nums[i]); //偶数数组
    }
    
    int count = 0; //(只能是一个奇数一个偶数才可以构成素数伴侣)
    if(odds.size() == 0 || evens.size() == 0){
        cout << count << endl; //缺少奇数或者偶数无法构成素数伴侣
    }
    else{
        vector<int> match(evens.size(), 0); //统计每个偶数的配对是哪个奇数
        for(int i = 0; i < odds.size(); i++){ //遍历每个奇数
            vector<bool> used(evens.size(), false); //对于当前的奇数 每一个偶数都没用过

            if(find(odds[i], evens, used, match)){  //能否找到配对的偶数
                count++;
            }
        }

        cout << count << endl;
    }
    
    
    
    return 0;
}

29.字符串加解密

#include <bits/stdc++.h>

using namespace std;

//encoder
void encoder(string str){
    for(int i = 0; i < str.size(); i++){
        if(isalpha(str[i])){
            if(str[i] >= 'a' && str[i] <= 'z'){//小写字母
                if(str[i] == 'z') str[i] = 'A';
                else{
                    str[i] = str[i] - 'a' + 'A' + 1;//变换大小写同时用后一个字母替换
                }
            }
            else{
                if(str[i] == 'Z') str[i] = 'a';
                else{
                    str[i] = str[i] - 'A' + 'a' + 1;//变换大小写同时用后一个字母替换
                }
            }
        }
        else if(isdigit(str[i])){
            if(str[i] == '9') str[i] = '0';
            else{
                str[i] = str[i] + 1;
            }
        }
    }
    
    cout << str << endl;
}

//decoder
void decoder(string str){
    for(int i = 0; i < str.size(); i++){
        if(isalpha(str[i])){
            if(str[i] >= 'a' && str[i] <= 'z'){//小写字母
                if(str[i] == 'a') str[i] = 'Z';
                else{
                    str[i] = str[i] - 'a' + 'A' - 1;//变换大小写同时用后一个字母替换
                }
            }
            else{
                if(str[i] == 'A') str[i] = 'z';
                else{
                    str[i] = str[i] - 'A' + 'a' - 1;//变换大小写同时用后一个字母替换
                }
            }
        }
        else if(isdigit(str[i])){
            if(str[i] == '0') str[i] = '9';
            else{
                str[i] = str[i] - 1;
            }
        }
    }
    
    cout << str << endl;
}

int main(){
    string yao_jia_mi_str = "";
    cin >> yao_jia_mi_str;
    string jia_guo_mi_str = "";
    cin >> jia_guo_mi_str;
    
    encoder(yao_jia_mi_str);
    decoder(jia_guo_mi_str);
    
    return 0;
}

30.字符串合并处理

#include <bits/stdc++.h>

using namespace std;

//char Intput[] = {"0123456789abcdefABCDEF"}; //输入参照字典(数字 + 大小写字母)
//int Output[] = "084c2a6e195d3b7f5d3b7f"; //输出参照字典(小写)
//char Output[] = {"084C2A6E195D3B7F5D3B7F"}; //输出参照字典(数字 + 大写字母)
unordered_map<char, char> mp = {
    {'0', '0'},  {'1', '8'},  {'2', '4'},  
    {'3', 'C'},  {'4', '2'},  {'5', 'A'},  
    {'6', '6'},  {'7', 'E'},  {'8', '1'},  
    {'9', '9'},  {'a', '5'},  {'b', 'D'},  
    {'c', '3'},  {'d', 'B'},  {'e', '7'},  
    {'f', 'F'},  {'A', '5'},  {'B', 'D'},  
    {'C', '3'},  {'D', 'B'},  {'E', '7'}, 
    {'F', 'F'}
};

void process(string s1, string s2, string& res){
    //合并
    string s = s1 + s2;
    
    //排序
    string odds = "", evens = "";
    for(int i = 0; i < s.size(); i++){
        if(i % 2 == 0){
            evens += s[i];
        }
        else{
            odds += s[i];
        }
    }
    sort(odds.begin(), odds.end());//cout << odds << endl;
    sort(evens.begin(), evens.end());//cout << evens << endl;   
    int idx = 0; string newS = "";
    while(idx < odds.size() || idx < evens.size()){
        if(idx < evens.size()) newS += evens[idx];
        if(idx < odds.size()) newS += odds[idx];      
        idx++;
    }   
    //cout << newS << endl;
    
    //转换(直接建立哈希表,键为转换前,值为转换后)
    //哈希表中存在进行转换,否则保留原字符
    for(int i = 0; i < newS.size(); i++){
        if(mp.find(newS[i]) != mp.end()){
            newS[i] = mp[newS[i]];
        }
    }   
    
    res = newS;
}

int main(){
    string s1 = "", s2 = "";
    
    while(cin >> s1 >> s2){
        string res = "";
        process(s1, s2, res);
        cout << res << endl;
    }
    
    return 0;
}
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
员工持股资料分析 华为公司概况 华为技术有限公司是中国广东深圳市的生产销售电信设备的员工持股的民营科技公司,于1988年成立于中国深圳。 主要营业范围:交换,传输,无线和数据通信类电信产品,在电信领域为世界各地的客户提供络设备、服务和解决方案。 总裁:任正非 董事长:孙亚芳 1999年、2000年、2001年 分别在印度、瑞典、美国设立研发中心 2008年 被商业周刊评为全球十大最有影响力的公司。 根据Informa的咨询报告,华为在移动设备市场领域排名全球第三。  全年共递交1737件PCT专利申请,据世界知识产权组织统计,在2008年专利申请公司(人)排名榜上排名第一;LTE专利数占全球10%以上 2009年 无线接入市场份额跻身全球第二 一、员工持股计划的积极作用  华为的内部股制度对吸引人才的作用是非常明显的。过去华为有种“1+1+1”的说法,即员工的收入中,工资、奖金、股票分红的收入比例是相当的。而其中股票是当员工进入公司一年以后,依据员工的职位、季度绩效、任职资格状况等因素来进行派发。   一般是用员工的年度奖金来购买。如果新员工的年度奖金还不够派发的股票额,公司会贷款给员工。而员工也是很乐意于这种贷款。因为,分红的比例历年以来都保持在70%的高位。  二、持股计划的实施程序   《华为基本法》第十七条、十八条关于知识资本化、价值分配的形式有所论述:“我们实行员工持股制度。一方面,普惠认同华为的模范员工,结成公司与员工的利益与命运共同体。另一方面,将不断地使最有责任心与才能的人进入公司的中坚层”、“华为可分配的价

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

wrdoct

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

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

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

打赏作者

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

抵扣说明:

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

余额充值