当前位置:   article > 正文

中国电信IT研发中心 2019校园招聘笔试F卷 编程题-2018.09.10_电信笔试有编程题吗

电信笔试有编程题吗

1

#include <bits/stdc++.h>
using namespace std;
int arr[26];
int main()
{
    string str;
    cin >> str;
    vector<int> vec;
    for(int i=0; i<str.size(); i++){
        int temp = str[i]-'a';
        arr[temp]++;
    }
    int minNum = 0;
    //找出最少的字符  一定要排除字符数量为0的情况
    for(int i=0; i<26; i++){
        if(arr[i] != 0){
            minNum = i;
            break;
        }
    }
    for(int i=0; i<26; i++){
        if(arr[i] < arr[minNum] && arr[i] != 0)
            minNum = i;
    }
    //将数量最少的字符对应的数字全部加入vec
    for(int i=0; i<26; i++){
        if(arr[i] == arr[minNum])
            vec.push_back(i);
    }
    for(int i=0; i<str.size(); i++){
        bool flag = true;
        int temp = str[i]-'a';
        for(int j=0; j<vec.size(); j++){//判断字符是否主要删除
            if(vec[j] == temp){
                flag = false;
                break;
            }

        }
        if(flag)
            cout << str[i];
    }
    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45

2
剑指offer原题 牛客网题解 点击链接

#include <iostream>
#include <vector>
#define min(a, b) (a<b ? a : b);
using namespace std;
int getUglyNumber(int index) {
    if(index < 7)
        return index;
    vector<int> res(index);
    res[0] = 1;
    int t2 = 0, t3 = 0, t5 = 0, i;
    for(i = 1; i < index; ++i){
        int minTemp = min(res[t2]*2, res[t3]*3);
        res[i] = min(res[t5]*5, minTemp);
        if(res[i] == res[t2]*2)
            t2++;
        if(res[i] == res[t3]*3)
            t3++;
        if(res[i] == res[t5]*5)
            t5++;
    }
    return res[index - 1];
}

int main()
{
    int n;
    cin >> n;
    cout << getUglyNumber(n) << endl;
    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

3

KMP扩展
参考链接1
参考链接2

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/134252
推荐阅读
相关标签
  

闽ICP备14008679号