赛码网3月17号模拟试题(C++)

写在前面:

最近开始准备找工作了,平时刷的一些题偶尔有时间总结下发到博客上来,防止以后搞忘,可以随时分析下。当然,要是解题思路不对,或者说有更好的方法,欢迎大家指出来。

进入正题:

概要: 总共2个题,一个小时的时间安排。题目难度适中偏简单。

第一题 翻译火星文

题目描述

小赛捡到一本火星史书,由于无法读懂里面的文字,小赛决定找一本字典,并尝试翻译其中的内容。

这道题其实很基本,就是读入字符串,可以用一个hash表来表示隐射关系,对于火星文的翻译部分,可以顺序读取之后判断是否需要翻译,时间复杂度O(n)。

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

using namespace std;

void process(string& s, unordered_map<string, string>& table){
    int start = 0, end = 0;
    int lens = s.size();
    string tmp;
    for(int i=0;i<lens;i++){
        if((s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z')){
            tmp.push_back(s[i]);
        }
        else{
            if(tmp.empty()) cout << s[i];
            else{
                if(table.find(tmp)!=table.end())    cout << table[tmp] << s[i];
                else    cout << tmp << s[i];
                tmp.clear();
            }
        }
    }
    if(!tmp.empty()){
        if(table.find(tmp)!=table.end())    cout << table[tmp];
        else    cout << tmp;
    }
    cout << endl;
}

int main(){
    unordered_map<string, string> table;
    string str;
    while(getline(cin, str)){
        if(str=="START")  continue;
        else if(str=="END") break;
        else{
            int pos = str.find(' ');
            string first = str.substr(0,pos), second = str.substr(pos+1);
            table[second] = first;
        }
    }
    while(getline(cin, str)){
        if(str=="START")  continue;
        else if(str=="END") break;
        else{
            process(str, table);
        }
    }
    return 0;
}

第二题 游戏币

题目描述

小赛酷爱游戏,在他卧室的抽屉里有n个游戏币,总面值m,游戏币的设置有1分的,2分的,5分的,而在小赛所拥有的游戏币中有些面值的游戏币可能没有,求一共有多少种可能的游戏币组合方式?

是一个比较经典的找零钱的题,但是由于这类题没遇到过,所以脑海里面第一想法就是固定前两位,然后判断第三位的暴力解法,最后在oj中也过了,说明测试用例不是很多,大家有什么比较好的方法可以回复一个。

//#include <bit/stdc++.h>
#include <iostream>

using namespace std;

int main(){
    int n = 0, m = 0;
    cin >> n >> m;
    int count = 0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            int tmp = i + 2*j + 5*(n-i-j);
            if(tmp == m)    ++count;
        }
    }
    cout << count << endl;
    return 0;
}

总结:

找工作路漫漫,但求不忘初心,回首对得起走过的路。

代码地址: [luuuyi/some_companies_test]

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值